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
|
@@ -294,7 +294,7 @@ var ts;
|
|
|
294
294
|
// The following is baselined as a literal template type without intervention
|
|
295
295
|
/** The version of the TypeScript compiler release */
|
|
296
296
|
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
|
|
297
|
-
ts.version = ts.versionMajorMinor + ".0-dev.
|
|
297
|
+
ts.version = ts.versionMajorMinor + ".0-dev.20210928";
|
|
298
298
|
/* @internal */
|
|
299
299
|
var Comparison;
|
|
300
300
|
(function (Comparison) {
|
|
@@ -8392,6 +8392,8 @@ var ts;
|
|
|
8392
8392
|
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),
|
|
8393
8393
|
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),
|
|
8394
8394
|
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),
|
|
8395
|
+
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."),
|
|
8396
|
+
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."),
|
|
8395
8397
|
Duplicate_identifier_0: diag(2300, ts.DiagnosticCategory.Error, "Duplicate_identifier_0_2300", "Duplicate identifier '{0}'."),
|
|
8396
8398
|
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."),
|
|
8397
8399
|
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."),
|
|
@@ -13179,7 +13181,7 @@ var ts;
|
|
|
13179
13181
|
switch (node.kind) {
|
|
13180
13182
|
case 269 /* ImportSpecifier */:
|
|
13181
13183
|
case 274 /* ExportSpecifier */:
|
|
13182
|
-
return node.parent.parent.isTypeOnly;
|
|
13184
|
+
return node.isTypeOnly || node.parent.parent.isTypeOnly;
|
|
13183
13185
|
case 267 /* NamespaceImport */:
|
|
13184
13186
|
return node.parent.isTypeOnly;
|
|
13185
13187
|
case 266 /* ImportClause */:
|
|
@@ -19990,7 +19992,8 @@ var ts;
|
|
|
19990
19992
|
var aParts = ts.getPathComponents(ts.getNormalizedAbsolutePath(a, cwd));
|
|
19991
19993
|
var bParts = ts.getPathComponents(ts.getNormalizedAbsolutePath(b, cwd));
|
|
19992
19994
|
var isDirectory = false;
|
|
19993
|
-
while (
|
|
19995
|
+
while (aParts.length >= 2 && bParts.length >= 2 &&
|
|
19996
|
+
!isNodeModulesOrScopedPackageDirectory(aParts[aParts.length - 2], getCanonicalFileName) &&
|
|
19994
19997
|
!isNodeModulesOrScopedPackageDirectory(bParts[bParts.length - 2], getCanonicalFileName) &&
|
|
19995
19998
|
getCanonicalFileName(aParts[aParts.length - 1]) === getCanonicalFileName(bParts[bParts.length - 1])) {
|
|
19996
19999
|
aParts.pop();
|
|
@@ -20002,7 +20005,7 @@ var ts;
|
|
|
20002
20005
|
// KLUDGE: Don't assume one 'node_modules' links to another. More likely a single directory inside the node_modules is the symlink.
|
|
20003
20006
|
// ALso, don't assume that an `@foo` directory is linked. More likely the contents of that are linked.
|
|
20004
20007
|
function isNodeModulesOrScopedPackageDirectory(s, getCanonicalFileName) {
|
|
20005
|
-
return getCanonicalFileName(s) === "node_modules" || ts.startsWith(s, "@");
|
|
20008
|
+
return s !== undefined && (getCanonicalFileName(s) === "node_modules" || ts.startsWith(s, "@"));
|
|
20006
20009
|
}
|
|
20007
20010
|
function stripLeadingDirectorySeparator(s) {
|
|
20008
20011
|
return ts.isAnyDirectorySeparator(s.charCodeAt(0)) ? s.slice(1) : undefined;
|
|
@@ -20633,10 +20636,6 @@ var ts;
|
|
|
20633
20636
|
|| !(isExpressionNode(useSite) || isShorthandPropertyNameUseSite(useSite));
|
|
20634
20637
|
}
|
|
20635
20638
|
ts.isValidTypeOnlyAliasUseSite = isValidTypeOnlyAliasUseSite;
|
|
20636
|
-
function typeOnlyDeclarationIsExport(typeOnlyDeclaration) {
|
|
20637
|
-
return typeOnlyDeclaration.kind === 274 /* ExportSpecifier */;
|
|
20638
|
-
}
|
|
20639
|
-
ts.typeOnlyDeclarationIsExport = typeOnlyDeclarationIsExport;
|
|
20640
20639
|
function isShorthandPropertyNameUseSite(useSite) {
|
|
20641
20640
|
return ts.isIdentifier(useSite) && ts.isShorthandPropertyAssignment(useSite.parent) && useSite.parent.name === useSite;
|
|
20642
20641
|
}
|
|
@@ -24658,8 +24657,9 @@ var ts;
|
|
|
24658
24657
|
: node;
|
|
24659
24658
|
}
|
|
24660
24659
|
// @api
|
|
24661
|
-
function createImportSpecifier(propertyName, name) {
|
|
24660
|
+
function createImportSpecifier(isTypeOnly, propertyName, name) {
|
|
24662
24661
|
var node = createBaseNode(269 /* ImportSpecifier */);
|
|
24662
|
+
node.isTypeOnly = isTypeOnly;
|
|
24663
24663
|
node.propertyName = propertyName;
|
|
24664
24664
|
node.name = name;
|
|
24665
24665
|
node.transformFlags |=
|
|
@@ -24669,10 +24669,11 @@ var ts;
|
|
|
24669
24669
|
return node;
|
|
24670
24670
|
}
|
|
24671
24671
|
// @api
|
|
24672
|
-
function updateImportSpecifier(node, propertyName, name) {
|
|
24673
|
-
return node.
|
|
24672
|
+
function updateImportSpecifier(node, isTypeOnly, propertyName, name) {
|
|
24673
|
+
return node.isTypeOnly !== isTypeOnly
|
|
24674
|
+
|| node.propertyName !== propertyName
|
|
24674
24675
|
|| node.name !== name
|
|
24675
|
-
? update(createImportSpecifier(propertyName, name), node)
|
|
24676
|
+
? update(createImportSpecifier(isTypeOnly, propertyName, name), node)
|
|
24676
24677
|
: node;
|
|
24677
24678
|
}
|
|
24678
24679
|
// @api
|
|
@@ -24733,8 +24734,9 @@ var ts;
|
|
|
24733
24734
|
: node;
|
|
24734
24735
|
}
|
|
24735
24736
|
// @api
|
|
24736
|
-
function createExportSpecifier(propertyName, name) {
|
|
24737
|
+
function createExportSpecifier(isTypeOnly, propertyName, name) {
|
|
24737
24738
|
var node = createBaseNode(274 /* ExportSpecifier */);
|
|
24739
|
+
node.isTypeOnly = isTypeOnly;
|
|
24738
24740
|
node.propertyName = asName(propertyName);
|
|
24739
24741
|
node.name = asName(name);
|
|
24740
24742
|
node.transformFlags |=
|
|
@@ -24744,10 +24746,11 @@ var ts;
|
|
|
24744
24746
|
return node;
|
|
24745
24747
|
}
|
|
24746
24748
|
// @api
|
|
24747
|
-
function updateExportSpecifier(node, propertyName, name) {
|
|
24748
|
-
return node.
|
|
24749
|
+
function updateExportSpecifier(node, isTypeOnly, propertyName, name) {
|
|
24750
|
+
return node.isTypeOnly !== isTypeOnly
|
|
24751
|
+
|| node.propertyName !== propertyName
|
|
24749
24752
|
|| node.name !== name
|
|
24750
|
-
? update(createExportSpecifier(propertyName, name), node)
|
|
24753
|
+
? update(createExportSpecifier(isTypeOnly, propertyName, name), node)
|
|
24751
24754
|
: node;
|
|
24752
24755
|
}
|
|
24753
24756
|
// @api
|
|
@@ -25855,7 +25858,7 @@ var ts;
|
|
|
25855
25858
|
/*decorators*/ undefined,
|
|
25856
25859
|
/*modifiers*/ undefined,
|
|
25857
25860
|
/*isTypeOnly*/ false, createNamedExports([
|
|
25858
|
-
createExportSpecifier(/*propertyName*/ undefined, exportName)
|
|
25861
|
+
createExportSpecifier(/*isTypeOnly*/ false, /*propertyName*/ undefined, exportName)
|
|
25859
25862
|
]));
|
|
25860
25863
|
}
|
|
25861
25864
|
//
|
|
@@ -29122,8 +29125,8 @@ var ts;
|
|
|
29122
29125
|
// Alias the imports if the names are used somewhere in the file.
|
|
29123
29126
|
// NOTE: We don't need to care about global import collisions as this is a module.
|
|
29124
29127
|
namedBindings = nodeFactory.createNamedImports(ts.map(helperNames, function (name) { return ts.isFileLevelUniqueName(sourceFile, name)
|
|
29125
|
-
? nodeFactory.createImportSpecifier(/*propertyName*/ undefined, nodeFactory.createIdentifier(name))
|
|
29126
|
-
: nodeFactory.createImportSpecifier(nodeFactory.createIdentifier(name), helperFactory.getUnscopedHelperName(name)); }));
|
|
29128
|
+
? nodeFactory.createImportSpecifier(/*isTypeOnly*/ false, /*propertyName*/ undefined, nodeFactory.createIdentifier(name))
|
|
29129
|
+
: nodeFactory.createImportSpecifier(/*isTypeOnly*/ false, nodeFactory.createIdentifier(name), helperFactory.getUnscopedHelperName(name)); }));
|
|
29127
29130
|
var parseNode = ts.getOriginalNode(sourceFile, ts.isSourceFile);
|
|
29128
29131
|
var emitNode = ts.getOrCreateEmitNode(parseNode);
|
|
29129
29132
|
emitNode.externalHelpers = true;
|
|
@@ -36250,27 +36253,74 @@ var ts;
|
|
|
36250
36253
|
var checkIdentifierIsKeyword = ts.isKeyword(token()) && !isIdentifier();
|
|
36251
36254
|
var checkIdentifierStart = scanner.getTokenPos();
|
|
36252
36255
|
var checkIdentifierEnd = scanner.getTextPos();
|
|
36253
|
-
var
|
|
36256
|
+
var isTypeOnly = false;
|
|
36254
36257
|
var propertyName;
|
|
36255
|
-
var
|
|
36256
|
-
|
|
36257
|
-
|
|
36258
|
-
|
|
36259
|
-
|
|
36260
|
-
|
|
36261
|
-
|
|
36262
|
-
|
|
36258
|
+
var canParseAsKeyword = true;
|
|
36259
|
+
var name = parseIdentifierName();
|
|
36260
|
+
if (name.escapedText === "type") {
|
|
36261
|
+
// If the first token of an import specifier is 'type', there are a lot of possibilities,
|
|
36262
|
+
// especially if we see 'as' afterwards:
|
|
36263
|
+
//
|
|
36264
|
+
// import { type } from "mod"; - isTypeOnly: false, name: type
|
|
36265
|
+
// import { type as } from "mod"; - isTypeOnly: true, name: as
|
|
36266
|
+
// import { type as as } from "mod"; - isTypeOnly: false, name: as, propertyName: type
|
|
36267
|
+
// import { type as as as } from "mod"; - isTypeOnly: true, name: as, propertyName: as
|
|
36268
|
+
if (token() === 127 /* AsKeyword */) {
|
|
36269
|
+
// { type as ...? }
|
|
36270
|
+
var firstAs = parseIdentifierName();
|
|
36271
|
+
if (token() === 127 /* AsKeyword */) {
|
|
36272
|
+
// { type as as ...? }
|
|
36273
|
+
var secondAs = parseIdentifierName();
|
|
36274
|
+
if (ts.tokenIsIdentifierOrKeyword(token())) {
|
|
36275
|
+
// { type as as something }
|
|
36276
|
+
isTypeOnly = true;
|
|
36277
|
+
propertyName = firstAs;
|
|
36278
|
+
name = parseNameWithKeywordCheck();
|
|
36279
|
+
canParseAsKeyword = false;
|
|
36280
|
+
}
|
|
36281
|
+
else {
|
|
36282
|
+
// { type as as }
|
|
36283
|
+
propertyName = name;
|
|
36284
|
+
name = secondAs;
|
|
36285
|
+
canParseAsKeyword = false;
|
|
36286
|
+
}
|
|
36287
|
+
}
|
|
36288
|
+
else if (ts.tokenIsIdentifierOrKeyword(token())) {
|
|
36289
|
+
// { type as something }
|
|
36290
|
+
propertyName = name;
|
|
36291
|
+
canParseAsKeyword = false;
|
|
36292
|
+
name = parseNameWithKeywordCheck();
|
|
36293
|
+
}
|
|
36294
|
+
else {
|
|
36295
|
+
// { type as }
|
|
36296
|
+
isTypeOnly = true;
|
|
36297
|
+
name = firstAs;
|
|
36298
|
+
}
|
|
36299
|
+
}
|
|
36300
|
+
else if (ts.tokenIsIdentifierOrKeyword(token())) {
|
|
36301
|
+
// { type something ...? }
|
|
36302
|
+
isTypeOnly = true;
|
|
36303
|
+
name = parseNameWithKeywordCheck();
|
|
36304
|
+
}
|
|
36263
36305
|
}
|
|
36264
|
-
|
|
36265
|
-
|
|
36306
|
+
if (canParseAsKeyword && token() === 127 /* AsKeyword */) {
|
|
36307
|
+
propertyName = name;
|
|
36308
|
+
parseExpected(127 /* AsKeyword */);
|
|
36309
|
+
name = parseNameWithKeywordCheck();
|
|
36266
36310
|
}
|
|
36267
36311
|
if (kind === 269 /* ImportSpecifier */ && checkIdentifierIsKeyword) {
|
|
36268
36312
|
parseErrorAt(checkIdentifierStart, checkIdentifierEnd, ts.Diagnostics.Identifier_expected);
|
|
36269
36313
|
}
|
|
36270
36314
|
var node = kind === 269 /* ImportSpecifier */
|
|
36271
|
-
? factory.createImportSpecifier(propertyName, name)
|
|
36272
|
-
: factory.createExportSpecifier(propertyName, name);
|
|
36315
|
+
? factory.createImportSpecifier(isTypeOnly, propertyName, name)
|
|
36316
|
+
: factory.createExportSpecifier(isTypeOnly, propertyName, name);
|
|
36273
36317
|
return finishNode(node, pos);
|
|
36318
|
+
function parseNameWithKeywordCheck() {
|
|
36319
|
+
checkIdentifierIsKeyword = ts.isKeyword(token()) && !isIdentifier();
|
|
36320
|
+
checkIdentifierStart = scanner.getTokenPos();
|
|
36321
|
+
checkIdentifierEnd = scanner.getTextPos();
|
|
36322
|
+
return parseIdentifierName();
|
|
36323
|
+
}
|
|
36274
36324
|
}
|
|
36275
36325
|
function parseNamespaceExport(pos) {
|
|
36276
36326
|
return finishNode(factory.createNamespaceExport(parseIdentifierName()), pos);
|
|
@@ -47100,6 +47150,7 @@ var ts;
|
|
|
47100
47150
|
getLocalTypeParametersOfClassOrInterfaceOrTypeAlias: getLocalTypeParametersOfClassOrInterfaceOrTypeAlias,
|
|
47101
47151
|
isDeclarationVisible: isDeclarationVisible,
|
|
47102
47152
|
isPropertyAccessible: isPropertyAccessible,
|
|
47153
|
+
getTypeOnlyAliasDeclaration: getTypeOnlyAliasDeclaration,
|
|
47103
47154
|
};
|
|
47104
47155
|
function getResolvedSignatureWorker(nodeIn, candidatesOutArray, argumentCount, checkMode) {
|
|
47105
47156
|
var node = ts.getParseTreeNode(nodeIn, ts.isCallLikeExpression);
|
|
@@ -48476,8 +48527,7 @@ var ts;
|
|
|
48476
48527
|
if (!ts.isValidTypeOnlyAliasUseSite(useSite)) {
|
|
48477
48528
|
var typeOnlyDeclaration = getTypeOnlyAliasDeclaration(symbol);
|
|
48478
48529
|
if (typeOnlyDeclaration) {
|
|
48479
|
-
var
|
|
48480
|
-
var message = isExport
|
|
48530
|
+
var message = typeOnlyDeclaration.kind === 274 /* ExportSpecifier */
|
|
48481
48531
|
? ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type
|
|
48482
48532
|
: ts.Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type;
|
|
48483
48533
|
var unescapedName = ts.unescapeLeadingUnderscores(name);
|
|
@@ -48488,7 +48538,7 @@ var ts;
|
|
|
48488
48538
|
function addTypeOnlyDeclarationRelatedInfo(diagnostic, typeOnlyDeclaration, unescapedName) {
|
|
48489
48539
|
if (!typeOnlyDeclaration)
|
|
48490
48540
|
return diagnostic;
|
|
48491
|
-
return ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(typeOnlyDeclaration,
|
|
48541
|
+
return ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(typeOnlyDeclaration, typeOnlyDeclaration.kind === 274 /* ExportSpecifier */ ? ts.Diagnostics._0_was_exported_here : ts.Diagnostics._0_was_imported_here, unescapedName));
|
|
48492
48542
|
}
|
|
48493
48543
|
function getIsDeferredContext(location, lastLocation) {
|
|
48494
48544
|
if (location.kind !== 213 /* ArrowFunction */ && location.kind !== 212 /* FunctionExpression */) {
|
|
@@ -48812,15 +48862,13 @@ var ts;
|
|
|
48812
48862
|
function checkAndReportErrorForResolvingImportAliasToTypeOnlySymbol(node, resolved) {
|
|
48813
48863
|
if (markSymbolOfAliasDeclarationIfTypeOnly(node, /*immediateTarget*/ undefined, resolved, /*overwriteEmpty*/ false) && !node.isTypeOnly) {
|
|
48814
48864
|
var typeOnlyDeclaration = getTypeOnlyAliasDeclaration(getSymbolOfNode(node));
|
|
48815
|
-
var isExport =
|
|
48865
|
+
var isExport = typeOnlyDeclaration.kind === 274 /* ExportSpecifier */;
|
|
48816
48866
|
var message = isExport
|
|
48817
48867
|
? ts.Diagnostics.An_import_alias_cannot_reference_a_declaration_that_was_exported_using_export_type
|
|
48818
48868
|
: ts.Diagnostics.An_import_alias_cannot_reference_a_declaration_that_was_imported_using_import_type;
|
|
48819
48869
|
var relatedMessage = isExport
|
|
48820
48870
|
? ts.Diagnostics._0_was_exported_here
|
|
48821
48871
|
: ts.Diagnostics._0_was_imported_here;
|
|
48822
|
-
// Non-null assertion is safe because the optionality comes from ImportClause,
|
|
48823
|
-
// but if an ImportClause was the typeOnlyDeclaration, it had to have a `name`.
|
|
48824
48872
|
var name = ts.unescapeLeadingUnderscores(typeOnlyDeclaration.name.escapedText);
|
|
48825
48873
|
ts.addRelatedInfo(error(node.moduleReference, message), ts.createDiagnosticForNode(typeOnlyDeclaration, relatedMessage, name));
|
|
48826
48874
|
}
|
|
@@ -49236,13 +49284,13 @@ var ts;
|
|
|
49236
49284
|
* and issue an error if so.
|
|
49237
49285
|
*
|
|
49238
49286
|
* @param aliasDeclaration The alias declaration not marked as type-only
|
|
49287
|
+
* @param immediateTarget The symbol to which the alias declaration immediately resolves
|
|
49288
|
+
* @param finalTarget The symbol to which the alias declaration ultimately resolves
|
|
49289
|
+
* @param overwriteEmpty Checks `resolvesToSymbol` for type-only declarations even if `aliasDeclaration`
|
|
49239
49290
|
* has already been marked as not resolving to a type-only alias. Used when recursively resolving qualified
|
|
49240
49291
|
* names of import aliases, e.g. `import C = a.b.C`. If namespace `a` is not found to be type-only, the
|
|
49241
49292
|
* import declaration will initially be marked as not resolving to a type-only symbol. But, namespace `b`
|
|
49242
49293
|
* must still be checked for a type-only marker, overwriting the previous negative result if found.
|
|
49243
|
-
* @param immediateTarget The symbol to which the alias declaration immediately resolves
|
|
49244
|
-
* @param finalTarget The symbol to which the alias declaration ultimately resolves
|
|
49245
|
-
* @param overwriteEmpty Checks `resolvesToSymbol` for type-only declarations even if `aliasDeclaration`
|
|
49246
49294
|
*/
|
|
49247
49295
|
function markSymbolOfAliasDeclarationIfTypeOnly(aliasDeclaration, immediateTarget, finalTarget, overwriteEmpty) {
|
|
49248
49296
|
if (!aliasDeclaration || ts.isPropertyAccessExpression(aliasDeclaration))
|
|
@@ -52375,7 +52423,7 @@ var ts;
|
|
|
52375
52423
|
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(
|
|
52376
52424
|
/*decorators*/ undefined,
|
|
52377
52425
|
/*modifiers*/ undefined,
|
|
52378
|
-
/*isTypeOnly*/ false, ts.factory.createNamedExports(ts.map(ts.flatMap(excessExports, function (e) { return getNamesOfDeclaration(e); }), function (id) { return ts.factory.createExportSpecifier(/*alias*/ undefined, id); })),
|
|
52426
|
+
/*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); })),
|
|
52379
52427
|
/*moduleSpecifier*/ undefined)], false))));
|
|
52380
52428
|
statements = __spreadArray(__spreadArray(__spreadArray([], statements.slice(0, nsIndex), true), [ns], false), statements.slice(nsIndex + 1), true);
|
|
52381
52429
|
}
|
|
@@ -52603,7 +52651,7 @@ var ts;
|
|
|
52603
52651
|
addResult(ts.factory.createExportDeclaration(
|
|
52604
52652
|
/*decorators*/ undefined,
|
|
52605
52653
|
/*modifiers*/ undefined,
|
|
52606
|
-
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(alias, localName)])), 0 /* None */);
|
|
52654
|
+
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, alias, localName)])), 0 /* None */);
|
|
52607
52655
|
context.tracker.trackSymbol(type.symbol, context.enclosingDeclaration, 111551 /* Value */);
|
|
52608
52656
|
}
|
|
52609
52657
|
else {
|
|
@@ -52636,7 +52684,7 @@ var ts;
|
|
|
52636
52684
|
addResult(ts.factory.createExportDeclaration(
|
|
52637
52685
|
/*decorators*/ undefined,
|
|
52638
52686
|
/*modifiers*/ undefined,
|
|
52639
|
-
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(name, localName)])), 0 /* None */);
|
|
52687
|
+
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, name, localName)])), 0 /* None */);
|
|
52640
52688
|
needsExportDeclaration = false;
|
|
52641
52689
|
needsPostExportDefault = false;
|
|
52642
52690
|
}
|
|
@@ -52694,7 +52742,7 @@ var ts;
|
|
|
52694
52742
|
addResult(ts.factory.createExportDeclaration(
|
|
52695
52743
|
/*decorators*/ undefined,
|
|
52696
52744
|
/*modifiers*/ undefined,
|
|
52697
|
-
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(getInternalSymbolName(symbol, symbolName), symbolName)])), 0 /* None */);
|
|
52745
|
+
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, getInternalSymbolName(symbol, symbolName), symbolName)])), 0 /* None */);
|
|
52698
52746
|
}
|
|
52699
52747
|
}
|
|
52700
52748
|
function includePrivateSymbol(symbol) {
|
|
@@ -52816,7 +52864,7 @@ var ts;
|
|
|
52816
52864
|
var target = aliasDecl && getTargetOfAliasDeclaration(aliasDecl, /*dontRecursivelyResolve*/ true);
|
|
52817
52865
|
includePrivateSymbol(target || s);
|
|
52818
52866
|
var targetName = target ? getInternalSymbolName(target, ts.unescapeLeadingUnderscores(target.escapedName)) : localName;
|
|
52819
|
-
return ts.factory.createExportSpecifier(name === targetName ? undefined : targetName, name);
|
|
52867
|
+
return ts.factory.createExportSpecifier(/*isTypeOnly*/ false, name === targetName ? undefined : targetName, name);
|
|
52820
52868
|
})))]);
|
|
52821
52869
|
addResult(ts.factory.createModuleDeclaration(
|
|
52822
52870
|
/*decorators*/ undefined,
|
|
@@ -52907,7 +52955,7 @@ var ts;
|
|
|
52907
52955
|
var defaultReplaced = ts.map(declarations, function (d) { return ts.isExportAssignment(d) && !d.isExportEquals && ts.isIdentifier(d.expression) ? ts.factory.createExportDeclaration(
|
|
52908
52956
|
/*decorators*/ undefined,
|
|
52909
52957
|
/*modifiers*/ undefined,
|
|
52910
|
-
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(d.expression, ts.factory.createIdentifier("default" /* Default */))])) : d; });
|
|
52958
|
+
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, d.expression, ts.factory.createIdentifier("default" /* Default */))])) : d; });
|
|
52911
52959
|
var exportModifierStripped = ts.every(defaultReplaced, function (d) { return ts.hasSyntacticModifier(d, 1 /* Export */); }) ? ts.map(defaultReplaced, removeExportModifier) : defaultReplaced;
|
|
52912
52960
|
fakespace = ts.factory.updateModuleDeclaration(fakespace, fakespace.decorators, fakespace.modifiers, fakespace.name, ts.factory.createModuleBlock(exportModifierStripped));
|
|
52913
52961
|
addResult(fakespace, modifierFlags); // namespaces can never be default exported
|
|
@@ -53058,7 +53106,8 @@ var ts;
|
|
|
53058
53106
|
var propertyName = node.propertyName;
|
|
53059
53107
|
addResult(ts.factory.createImportDeclaration(
|
|
53060
53108
|
/*decorators*/ undefined,
|
|
53061
|
-
/*modifiers*/ undefined, ts.factory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, ts.factory.createNamedImports([ts.factory.createImportSpecifier(
|
|
53109
|
+
/*modifiers*/ undefined, ts.factory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, ts.factory.createNamedImports([ts.factory.createImportSpecifier(
|
|
53110
|
+
/*isTypeOnly*/ false, propertyName && ts.isIdentifier(propertyName) ? ts.factory.createIdentifier(ts.idText(propertyName)) : undefined, ts.factory.createIdentifier(localName))])), ts.factory.createStringLiteral(specifier_1),
|
|
53062
53111
|
/*importClause*/ undefined), 0 /* None */);
|
|
53063
53112
|
break;
|
|
53064
53113
|
}
|
|
@@ -53142,7 +53191,8 @@ var ts;
|
|
|
53142
53191
|
/*modifiers*/ undefined, ts.factory.createImportClause(
|
|
53143
53192
|
/*isTypeOnly*/ false,
|
|
53144
53193
|
/*importClause*/ undefined, ts.factory.createNamedImports([
|
|
53145
|
-
ts.factory.createImportSpecifier(
|
|
53194
|
+
ts.factory.createImportSpecifier(
|
|
53195
|
+
/*isTypeOnly*/ false, localName !== verbatimTargetName ? ts.factory.createIdentifier(verbatimTargetName) : undefined, ts.factory.createIdentifier(localName))
|
|
53146
53196
|
])), ts.factory.createStringLiteral(getSpecifierForModuleSymbol(target.parent || target, context)),
|
|
53147
53197
|
/*assertClause*/ undefined), 0 /* None */);
|
|
53148
53198
|
break;
|
|
@@ -53178,7 +53228,7 @@ var ts;
|
|
|
53178
53228
|
addResult(ts.factory.createExportDeclaration(
|
|
53179
53229
|
/*decorators*/ undefined,
|
|
53180
53230
|
/*modifiers*/ undefined,
|
|
53181
|
-
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(localName !== targetName ? targetName : undefined, localName)]), specifier), 0 /* None */);
|
|
53231
|
+
/*isTypeOnly*/ false, ts.factory.createNamedExports([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, localName !== targetName ? targetName : undefined, localName)]), specifier), 0 /* None */);
|
|
53182
53232
|
}
|
|
53183
53233
|
/**
|
|
53184
53234
|
* Returns `true` if an export assignment or declaration was produced for the symbol
|
|
@@ -56673,6 +56723,23 @@ var ts;
|
|
|
56673
56723
|
function getIsLateCheckFlag(s) {
|
|
56674
56724
|
return ts.getCheckFlags(s) & 4096 /* Late */;
|
|
56675
56725
|
}
|
|
56726
|
+
function forEachMappedTypePropertyKeyTypeAndIndexSignatureKeyType(type, include, stringsOnly, cb) {
|
|
56727
|
+
for (var _i = 0, _a = getPropertiesOfType(type); _i < _a.length; _i++) {
|
|
56728
|
+
var prop = _a[_i];
|
|
56729
|
+
cb(getLiteralTypeFromProperty(prop, include));
|
|
56730
|
+
}
|
|
56731
|
+
if (type.flags & 1 /* Any */) {
|
|
56732
|
+
cb(stringType);
|
|
56733
|
+
}
|
|
56734
|
+
else {
|
|
56735
|
+
for (var _b = 0, _c = getIndexInfosOfType(type); _b < _c.length; _b++) {
|
|
56736
|
+
var info = _c[_b];
|
|
56737
|
+
if (!stringsOnly || info.keyType.flags & (4 /* String */ | 134217728 /* TemplateLiteral */)) {
|
|
56738
|
+
cb(info.keyType);
|
|
56739
|
+
}
|
|
56740
|
+
}
|
|
56741
|
+
}
|
|
56742
|
+
}
|
|
56676
56743
|
/** Resolve the members of a mapped type { [P in K]: T } */
|
|
56677
56744
|
function resolveMappedTypeMembers(type) {
|
|
56678
56745
|
var members = ts.createSymbolTable();
|
|
@@ -56690,21 +56757,7 @@ var ts;
|
|
|
56690
56757
|
var include = keyofStringsOnly ? 128 /* StringLiteral */ : 8576 /* StringOrNumberLiteralOrUnique */;
|
|
56691
56758
|
if (isMappedTypeWithKeyofConstraintDeclaration(type)) {
|
|
56692
56759
|
// We have a { [P in keyof T]: X }
|
|
56693
|
-
|
|
56694
|
-
var prop = _a[_i];
|
|
56695
|
-
addMemberForKeyType(getLiteralTypeFromProperty(prop, include));
|
|
56696
|
-
}
|
|
56697
|
-
if (modifiersType.flags & 1 /* Any */) {
|
|
56698
|
-
addMemberForKeyType(stringType);
|
|
56699
|
-
}
|
|
56700
|
-
else {
|
|
56701
|
-
for (var _b = 0, _c = getIndexInfosOfType(modifiersType); _b < _c.length; _b++) {
|
|
56702
|
-
var info = _c[_b];
|
|
56703
|
-
if (!keyofStringsOnly || info.keyType.flags & (4 /* String */ | 134217728 /* TemplateLiteral */)) {
|
|
56704
|
-
addMemberForKeyType(info.keyType);
|
|
56705
|
-
}
|
|
56706
|
-
}
|
|
56707
|
-
}
|
|
56760
|
+
forEachMappedTypePropertyKeyTypeAndIndexSignatureKeyType(modifiersType, include, keyofStringsOnly, addMemberForKeyType);
|
|
56708
56761
|
}
|
|
56709
56762
|
else {
|
|
56710
56763
|
forEachType(getLowerBoundOfKeyType(constraintType), addMemberForKeyType);
|
|
@@ -59821,18 +59874,56 @@ var ts;
|
|
|
59821
59874
|
type.resolvedStringIndexType || (type.resolvedStringIndexType = createIndexType(type, /*stringsOnly*/ true)) :
|
|
59822
59875
|
type.resolvedIndexType || (type.resolvedIndexType = createIndexType(type, /*stringsOnly*/ false));
|
|
59823
59876
|
}
|
|
59824
|
-
|
|
59825
|
-
|
|
59826
|
-
|
|
59827
|
-
|
|
59828
|
-
|
|
59829
|
-
|
|
59830
|
-
|
|
59831
|
-
|
|
59832
|
-
var
|
|
59833
|
-
|
|
59834
|
-
|
|
59835
|
-
|
|
59877
|
+
/**
|
|
59878
|
+
* This roughly mirrors `resolveMappedTypeMembers` in the nongeneric case, except only reports a union of the keys calculated,
|
|
59879
|
+
* rather than manufacturing the properties. We can't just fetch the `constraintType` since that would ignore mappings
|
|
59880
|
+
* and mapping the `constraintType` directly ignores how mapped types map _properties_ and not keys (thus ignoring subtype
|
|
59881
|
+
* reduction in the constraintType) when possible.
|
|
59882
|
+
* @param noIndexSignatures Indicates if _string_ index signatures should be elided. (other index signatures are always reported)
|
|
59883
|
+
*/
|
|
59884
|
+
function getIndexTypeForMappedType(type, stringsOnly, noIndexSignatures) {
|
|
59885
|
+
var typeParameter = getTypeParameterFromMappedType(type);
|
|
59886
|
+
var constraintType = getConstraintTypeFromMappedType(type);
|
|
59887
|
+
var nameType = getNameTypeFromMappedType(type.target || type);
|
|
59888
|
+
if (!nameType && !noIndexSignatures) {
|
|
59889
|
+
// no mapping and no filtering required, just quickly bail to returning the constraint in the common case
|
|
59890
|
+
return constraintType;
|
|
59891
|
+
}
|
|
59892
|
+
var keyTypes = [];
|
|
59893
|
+
if (isMappedTypeWithKeyofConstraintDeclaration(type)) {
|
|
59894
|
+
// We have a { [P in keyof T]: X }
|
|
59895
|
+
// `getApparentType` on the T in a generic mapped type can trigger a circularity
|
|
59896
|
+
// (conditionals and `infer` types create a circular dependency in the constraint resolution)
|
|
59897
|
+
// so we only eagerly manifest the keys if the constraint is nongeneric
|
|
59898
|
+
if (!isGenericIndexType(constraintType)) {
|
|
59899
|
+
var modifiersType = getApparentType(getModifiersTypeFromMappedType(type)); // The 'T' in 'keyof T'
|
|
59900
|
+
forEachMappedTypePropertyKeyTypeAndIndexSignatureKeyType(modifiersType, 8576 /* StringOrNumberLiteralOrUnique */, stringsOnly, addMemberForKeyType);
|
|
59901
|
+
}
|
|
59902
|
+
else {
|
|
59903
|
+
// we have a generic index and a homomorphic mapping (but a distributive key remapping) - we need to defer the whole `keyof whatever` for later
|
|
59904
|
+
// since it's not safe to resolve the shape of modifier type
|
|
59905
|
+
return getIndexTypeForGenericType(type, stringsOnly);
|
|
59906
|
+
}
|
|
59907
|
+
}
|
|
59908
|
+
else {
|
|
59909
|
+
forEachType(getLowerBoundOfKeyType(constraintType), addMemberForKeyType);
|
|
59910
|
+
}
|
|
59911
|
+
if (isGenericIndexType(constraintType)) { // include the generic component in the resulting type
|
|
59912
|
+
forEachType(constraintType, addMemberForKeyType);
|
|
59913
|
+
}
|
|
59914
|
+
// we had to pick apart the constraintType to potentially map/filter it - compare the final resulting list with the original constraintType,
|
|
59915
|
+
// so we can return the union that preserves aliases/origin data if possible
|
|
59916
|
+
var result = noIndexSignatures ? filterType(getUnionType(keyTypes), function (t) { return !(t.flags & (1 /* Any */ | 4 /* String */)); }) : getUnionType(keyTypes);
|
|
59917
|
+
if (result.flags & 1048576 /* Union */ && constraintType.flags & 1048576 /* Union */ && getTypeListId(result.types) === getTypeListId(constraintType.types)) {
|
|
59918
|
+
return constraintType;
|
|
59919
|
+
}
|
|
59920
|
+
return result;
|
|
59921
|
+
function addMemberForKeyType(keyType) {
|
|
59922
|
+
var propNameType = nameType ? instantiateType(nameType, appendTypeMapping(type.mapper, typeParameter, keyType)) : keyType;
|
|
59923
|
+
// `keyof` currently always returns `string | number` for concrete `string` index signatures - the below ternary keeps that behavior for mapped types
|
|
59924
|
+
// See `getLiteralTypeFromProperties` where there's a similar ternary to cause the same behavior.
|
|
59925
|
+
keyTypes.push(propNameType === stringType ? stringOrNumberType : propNameType);
|
|
59926
|
+
}
|
|
59836
59927
|
}
|
|
59837
59928
|
// 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
|
|
59838
59929
|
// 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
|
|
@@ -59890,7 +59981,7 @@ var ts;
|
|
|
59890
59981
|
return type.flags & 1048576 /* Union */ ? getIntersectionType(ts.map(type.types, function (t) { return getIndexType(t, stringsOnly, noIndexSignatures); })) :
|
|
59891
59982
|
type.flags & 2097152 /* Intersection */ ? getUnionType(ts.map(type.types, function (t) { return getIndexType(t, stringsOnly, noIndexSignatures); })) :
|
|
59892
59983
|
type.flags & 58982400 /* InstantiableNonPrimitive */ || isGenericTupleType(type) || isGenericMappedType(type) && !hasDistributiveNameType(type) ? getIndexTypeForGenericType(type, stringsOnly) :
|
|
59893
|
-
ts.getObjectFlags(type) & 32 /* Mapped */ ? getIndexTypeForMappedType(type, noIndexSignatures) :
|
|
59984
|
+
ts.getObjectFlags(type) & 32 /* Mapped */ ? getIndexTypeForMappedType(type, stringsOnly, noIndexSignatures) :
|
|
59894
59985
|
type === wildcardType ? wildcardType :
|
|
59895
59986
|
type.flags & 2 /* Unknown */ ? neverType :
|
|
59896
59987
|
type.flags & (1 /* Any */ | 131072 /* Never */) ? keyofConstraintType :
|
|
@@ -63649,24 +63740,24 @@ var ts;
|
|
|
63649
63740
|
}
|
|
63650
63741
|
}
|
|
63651
63742
|
else if (target.flags & 4194304 /* Index */) {
|
|
63652
|
-
var
|
|
63743
|
+
var targetType_1 = target.type;
|
|
63653
63744
|
// A keyof S is related to a keyof T if T is related to S.
|
|
63654
63745
|
if (source.flags & 4194304 /* Index */) {
|
|
63655
|
-
if (result = isRelatedTo(
|
|
63746
|
+
if (result = isRelatedTo(targetType_1, source.type, /*reportErrors*/ false)) {
|
|
63656
63747
|
return result;
|
|
63657
63748
|
}
|
|
63658
63749
|
}
|
|
63659
|
-
if (isTupleType(
|
|
63750
|
+
if (isTupleType(targetType_1)) {
|
|
63660
63751
|
// An index type can have a tuple type target when the tuple type contains variadic elements.
|
|
63661
63752
|
// Check if the source is related to the known keys of the tuple type.
|
|
63662
|
-
if (result = isRelatedTo(source, getKnownKeysOfTupleType(
|
|
63753
|
+
if (result = isRelatedTo(source, getKnownKeysOfTupleType(targetType_1), reportErrors)) {
|
|
63663
63754
|
return result;
|
|
63664
63755
|
}
|
|
63665
63756
|
}
|
|
63666
63757
|
else {
|
|
63667
63758
|
// A type S is assignable to keyof T if S is assignable to keyof C, where C is the
|
|
63668
63759
|
// simplified form of T or, if T doesn't simplify, the constraint of T.
|
|
63669
|
-
var constraint = getSimplifiedTypeOrConstraint(
|
|
63760
|
+
var constraint = getSimplifiedTypeOrConstraint(targetType_1);
|
|
63670
63761
|
if (constraint) {
|
|
63671
63762
|
// We require Ternary.True here such that circular constraints don't cause
|
|
63672
63763
|
// false positives. For example, given 'T extends { [K in keyof T]: string }',
|
|
@@ -63676,6 +63767,30 @@ var ts;
|
|
|
63676
63767
|
return -1 /* True */;
|
|
63677
63768
|
}
|
|
63678
63769
|
}
|
|
63770
|
+
else if (isGenericMappedType(targetType_1)) {
|
|
63771
|
+
// generic mapped types that don't simplify or have a constraint still have a very simple set of keys we can compare against
|
|
63772
|
+
// - their nameType or constraintType.
|
|
63773
|
+
// In many ways, this comparison is a deferred version of what `getIndexTypeForMappedType` does to actually resolve the keys for _non_-generic types
|
|
63774
|
+
var nameType_1 = getNameTypeFromMappedType(targetType_1);
|
|
63775
|
+
var constraintType = getConstraintTypeFromMappedType(targetType_1);
|
|
63776
|
+
var targetKeys = void 0;
|
|
63777
|
+
if (nameType_1 && isMappedTypeWithKeyofConstraintDeclaration(targetType_1)) {
|
|
63778
|
+
// we need to get the apparent mappings and union them with the generic mappings, since some properties may be
|
|
63779
|
+
// missing from the `constraintType` which will otherwise be mapped in the object
|
|
63780
|
+
var modifiersType = getApparentType(getModifiersTypeFromMappedType(targetType_1));
|
|
63781
|
+
var mappedKeys_1 = [];
|
|
63782
|
+
forEachMappedTypePropertyKeyTypeAndIndexSignatureKeyType(modifiersType, 8576 /* StringOrNumberLiteralOrUnique */,
|
|
63783
|
+
/*stringsOnly*/ false, function (t) { return void mappedKeys_1.push(instantiateType(nameType_1, appendTypeMapping(targetType_1.mapper, getTypeParameterFromMappedType(targetType_1), t))); });
|
|
63784
|
+
// 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)
|
|
63785
|
+
targetKeys = getUnionType(__spreadArray(__spreadArray([], mappedKeys_1, true), [nameType_1], false));
|
|
63786
|
+
}
|
|
63787
|
+
else {
|
|
63788
|
+
targetKeys = nameType_1 || constraintType;
|
|
63789
|
+
}
|
|
63790
|
+
if (isRelatedTo(source, targetKeys, reportErrors) === -1 /* True */) {
|
|
63791
|
+
return -1 /* True */;
|
|
63792
|
+
}
|
|
63793
|
+
}
|
|
63679
63794
|
}
|
|
63680
63795
|
}
|
|
63681
63796
|
else if (target.flags & 8388608 /* IndexedAccess */) {
|
|
@@ -66706,8 +66821,16 @@ var ts;
|
|
|
66706
66821
|
function inferToTemplateLiteralType(source, target) {
|
|
66707
66822
|
var matches = inferTypesFromTemplateLiteralType(source, target);
|
|
66708
66823
|
var types = target.types;
|
|
66709
|
-
|
|
66710
|
-
|
|
66824
|
+
// When the target template literal contains only placeholders (meaning that inference is intended to extract
|
|
66825
|
+
// single characters and remainder strings) and inference fails to produce matches, we want to infer 'never' for
|
|
66826
|
+
// each placeholder such that instantiation with the inferred value(s) produces 'never', a type for which an
|
|
66827
|
+
// assignment check will fail. If we make no inferences, we'll likely end up with the constraint 'string' which,
|
|
66828
|
+
// upon instantiation, would collapse all the placeholders to just 'string', and an assignment check might
|
|
66829
|
+
// succeed. That would be a pointless and confusing outcome.
|
|
66830
|
+
if (matches || ts.every(target.texts, function (s) { return s.length === 0; })) {
|
|
66831
|
+
for (var i = 0; i < types.length; i++) {
|
|
66832
|
+
inferFromTypes(matches ? matches[i] : neverType, types[i]);
|
|
66833
|
+
}
|
|
66711
66834
|
}
|
|
66712
66835
|
}
|
|
66713
66836
|
function inferFromObjectTypes(source, target) {
|
|
@@ -70424,9 +70547,9 @@ var ts;
|
|
|
70424
70547
|
return getTypeOfPropertyOfContextualType(type, getSymbolOfNode(element).escapedName);
|
|
70425
70548
|
}
|
|
70426
70549
|
if (element.name) {
|
|
70427
|
-
var
|
|
70550
|
+
var nameType_2 = getLiteralTypeFromPropertyName(element.name);
|
|
70428
70551
|
// We avoid calling getApplicableIndexInfo here because it performs potentially expensive intersection reduction.
|
|
70429
|
-
return mapType(type, function (t) { var _a; return (_a = findApplicableIndexInfo(getIndexInfosOfStructuredType(t),
|
|
70552
|
+
return mapType(type, function (t) { var _a; return (_a = findApplicableIndexInfo(getIndexInfosOfStructuredType(t), nameType_2)) === null || _a === void 0 ? void 0 : _a.type; }, /*noReductions*/ true);
|
|
70430
70553
|
}
|
|
70431
70554
|
}
|
|
70432
70555
|
return undefined;
|
|
@@ -82569,11 +82692,15 @@ var ts;
|
|
|
82569
82692
|
}
|
|
82570
82693
|
function checkGrammarExportDeclaration(node) {
|
|
82571
82694
|
var _a;
|
|
82572
|
-
|
|
82573
|
-
|
|
82574
|
-
|
|
82695
|
+
if (node.isTypeOnly) {
|
|
82696
|
+
if (((_a = node.exportClause) === null || _a === void 0 ? void 0 : _a.kind) === 272 /* NamedExports */) {
|
|
82697
|
+
return checkGrammarNamedImportsOrExports(node.exportClause);
|
|
82698
|
+
}
|
|
82699
|
+
else {
|
|
82700
|
+
return grammarErrorOnNode(node, ts.Diagnostics.Only_named_exports_may_use_export_type);
|
|
82701
|
+
}
|
|
82575
82702
|
}
|
|
82576
|
-
return
|
|
82703
|
+
return false;
|
|
82577
82704
|
}
|
|
82578
82705
|
function checkGrammarModuleElementContext(node, errorMessage) {
|
|
82579
82706
|
var isInAppropriateContext = node.parent.kind === 303 /* SourceFile */ || node.parent.kind === 261 /* ModuleBlock */ || node.parent.kind === 260 /* ModuleDeclaration */;
|
|
@@ -86248,11 +86375,24 @@ var ts;
|
|
|
86248
86375
|
return ambientModulesCache;
|
|
86249
86376
|
}
|
|
86250
86377
|
function checkGrammarImportClause(node) {
|
|
86378
|
+
var _a;
|
|
86251
86379
|
if (node.isTypeOnly && node.name && node.namedBindings) {
|
|
86252
86380
|
return grammarErrorOnNode(node, ts.Diagnostics.A_type_only_import_can_specify_a_default_import_or_named_bindings_but_not_both);
|
|
86253
86381
|
}
|
|
86382
|
+
if (node.isTypeOnly && ((_a = node.namedBindings) === null || _a === void 0 ? void 0 : _a.kind) === 268 /* NamedImports */) {
|
|
86383
|
+
return checkGrammarNamedImportsOrExports(node.namedBindings);
|
|
86384
|
+
}
|
|
86254
86385
|
return false;
|
|
86255
86386
|
}
|
|
86387
|
+
function checkGrammarNamedImportsOrExports(namedBindings) {
|
|
86388
|
+
return !!ts.forEach(namedBindings.elements, function (specifier) {
|
|
86389
|
+
if (specifier.isTypeOnly) {
|
|
86390
|
+
return grammarErrorOnFirstToken(specifier, specifier.kind === 269 /* ImportSpecifier */
|
|
86391
|
+
? ts.Diagnostics.The_type_modifier_cannot_be_used_on_a_named_import_when_import_type_is_used_on_its_import_statement
|
|
86392
|
+
: ts.Diagnostics.The_type_modifier_cannot_be_used_on_a_named_export_when_export_type_is_used_on_its_export_statement);
|
|
86393
|
+
}
|
|
86394
|
+
});
|
|
86395
|
+
}
|
|
86256
86396
|
function checkGrammarImportCallExpression(node) {
|
|
86257
86397
|
if (moduleKind === ts.ModuleKind.ES2015) {
|
|
86258
86398
|
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);
|
|
@@ -86984,7 +87124,7 @@ var ts;
|
|
|
86984
87124
|
return factory.updateNamedImports(node, nodesVisitor(node.elements, visitor, ts.isImportSpecifier));
|
|
86985
87125
|
case 269 /* ImportSpecifier */:
|
|
86986
87126
|
ts.Debug.type(node);
|
|
86987
|
-
return factory.updateImportSpecifier(node, nodeVisitor(node.propertyName, visitor, ts.isIdentifier), nodeVisitor(node.name, visitor, ts.isIdentifier));
|
|
87127
|
+
return factory.updateImportSpecifier(node, node.isTypeOnly, nodeVisitor(node.propertyName, visitor, ts.isIdentifier), nodeVisitor(node.name, visitor, ts.isIdentifier));
|
|
86988
87128
|
case 270 /* ExportAssignment */:
|
|
86989
87129
|
ts.Debug.type(node);
|
|
86990
87130
|
return factory.updateExportAssignment(node, nodesVisitor(node.decorators, visitor, ts.isDecorator), nodesVisitor(node.modifiers, visitor, ts.isModifier), nodeVisitor(node.expression, visitor, ts.isExpression));
|
|
@@ -86996,7 +87136,7 @@ var ts;
|
|
|
86996
87136
|
return factory.updateNamedExports(node, nodesVisitor(node.elements, visitor, ts.isExportSpecifier));
|
|
86997
87137
|
case 274 /* ExportSpecifier */:
|
|
86998
87138
|
ts.Debug.type(node);
|
|
86999
|
-
return factory.updateExportSpecifier(node, nodeVisitor(node.propertyName, visitor, ts.isIdentifier), nodeVisitor(node.name, visitor, ts.isIdentifier));
|
|
87139
|
+
return factory.updateExportSpecifier(node, node.isTypeOnly, nodeVisitor(node.propertyName, visitor, ts.isIdentifier), nodeVisitor(node.name, visitor, ts.isIdentifier));
|
|
87000
87140
|
// Module references
|
|
87001
87141
|
case 276 /* ExternalModuleReference */:
|
|
87002
87142
|
ts.Debug.type(node);
|
|
@@ -90937,9 +91077,11 @@ var ts;
|
|
|
90937
91077
|
return shouldEmitAliasDeclaration(node) ? node : undefined;
|
|
90938
91078
|
}
|
|
90939
91079
|
else {
|
|
90940
|
-
// Elide named imports if all of its import specifiers are elided.
|
|
91080
|
+
// Elide named imports if all of its import specifiers are elided and settings allow.
|
|
91081
|
+
var allowEmpty = compilerOptions.preserveValueImports && (compilerOptions.importsNotUsedAsValues === 1 /* Preserve */ ||
|
|
91082
|
+
compilerOptions.importsNotUsedAsValues === 2 /* Error */);
|
|
90941
91083
|
var elements = ts.visitNodes(node.elements, visitImportSpecifier, ts.isImportSpecifier);
|
|
90942
|
-
return ts.some(elements) ? factory.updateNamedImports(node, elements) : undefined;
|
|
91084
|
+
return allowEmpty || ts.some(elements) ? factory.updateNamedImports(node, elements) : undefined;
|
|
90943
91085
|
}
|
|
90944
91086
|
}
|
|
90945
91087
|
/**
|
|
@@ -90948,7 +91090,7 @@ var ts;
|
|
|
90948
91090
|
* @param node The import specifier node.
|
|
90949
91091
|
*/
|
|
90950
91092
|
function visitImportSpecifier(node) {
|
|
90951
|
-
return shouldEmitAliasDeclaration(node) ? node : undefined;
|
|
91093
|
+
return !node.isTypeOnly && shouldEmitAliasDeclaration(node) ? node : undefined;
|
|
90952
91094
|
}
|
|
90953
91095
|
/**
|
|
90954
91096
|
* Visits an export assignment, eliding it if it does not contain a clause that resolves
|
|
@@ -90977,12 +91119,10 @@ var ts;
|
|
|
90977
91119
|
// type checker doesn't know about any exports
|
|
90978
91120
|
return node;
|
|
90979
91121
|
}
|
|
90980
|
-
if (!resolver.isValueAliasDeclaration(node)) {
|
|
90981
|
-
// Elide the export declaration if it does not export a value.
|
|
90982
|
-
return undefined;
|
|
90983
|
-
}
|
|
90984
91122
|
// Elide the export declaration if all of its named exports are elided.
|
|
90985
|
-
var
|
|
91123
|
+
var allowEmpty = !!node.moduleSpecifier && (compilerOptions.importsNotUsedAsValues === 1 /* Preserve */ ||
|
|
91124
|
+
compilerOptions.importsNotUsedAsValues === 2 /* Error */);
|
|
91125
|
+
var exportClause = ts.visitNode(node.exportClause, function (bindings) { return visitNamedExportBindings(bindings, allowEmpty); }, ts.isNamedExportBindings);
|
|
90986
91126
|
return exportClause
|
|
90987
91127
|
? factory.updateExportDeclaration(node,
|
|
90988
91128
|
/*decorators*/ undefined,
|
|
@@ -90995,16 +91135,16 @@ var ts;
|
|
|
90995
91135
|
*
|
|
90996
91136
|
* @param node The named exports node.
|
|
90997
91137
|
*/
|
|
90998
|
-
function visitNamedExports(node) {
|
|
91138
|
+
function visitNamedExports(node, allowEmpty) {
|
|
90999
91139
|
// Elide the named exports if all of its export specifiers were elided.
|
|
91000
91140
|
var elements = ts.visitNodes(node.elements, visitExportSpecifier, ts.isExportSpecifier);
|
|
91001
|
-
return ts.some(elements) ? factory.updateNamedExports(node, elements) : undefined;
|
|
91141
|
+
return allowEmpty || ts.some(elements) ? factory.updateNamedExports(node, elements) : undefined;
|
|
91002
91142
|
}
|
|
91003
91143
|
function visitNamespaceExports(node) {
|
|
91004
91144
|
return factory.updateNamespaceExport(node, ts.visitNode(node.name, visitor, ts.isIdentifier));
|
|
91005
91145
|
}
|
|
91006
|
-
function visitNamedExportBindings(node) {
|
|
91007
|
-
return ts.isNamespaceExport(node) ? visitNamespaceExports(node) : visitNamedExports(node);
|
|
91146
|
+
function visitNamedExportBindings(node, allowEmpty) {
|
|
91147
|
+
return ts.isNamespaceExport(node) ? visitNamespaceExports(node) : visitNamedExports(node, allowEmpty);
|
|
91008
91148
|
}
|
|
91009
91149
|
/**
|
|
91010
91150
|
* Visits an export specifier, eliding it if it does not resolve to a value.
|
|
@@ -91013,7 +91153,7 @@ var ts;
|
|
|
91013
91153
|
*/
|
|
91014
91154
|
function visitExportSpecifier(node) {
|
|
91015
91155
|
// Elide an export specifier if it does not reference a value.
|
|
91016
|
-
return resolver.isValueAliasDeclaration(node) ? node : undefined;
|
|
91156
|
+
return !node.isTypeOnly && resolver.isValueAliasDeclaration(node) ? node : undefined;
|
|
91017
91157
|
}
|
|
91018
91158
|
/**
|
|
91019
91159
|
* Determines whether to emit an import equals declaration.
|
|
@@ -94614,7 +94754,7 @@ var ts;
|
|
|
94614
94754
|
currentFileState.utilizedImplicitRuntimeImports.set(importSource, specifierSourceImports);
|
|
94615
94755
|
}
|
|
94616
94756
|
var generatedName = factory.createUniqueName("_" + name, 16 /* Optimistic */ | 32 /* FileLevel */ | 64 /* AllowNameSubstitution */);
|
|
94617
|
-
var specifier = factory.createImportSpecifier(factory.createIdentifier(name), generatedName);
|
|
94757
|
+
var specifier = factory.createImportSpecifier(/*isTypeOnly*/ false, factory.createIdentifier(name), generatedName);
|
|
94618
94758
|
generatedName.generatedImportReference = specifier;
|
|
94619
94759
|
specifierSourceImports.set(name, specifier);
|
|
94620
94760
|
return generatedName;
|
|
@@ -104330,7 +104470,7 @@ var ts;
|
|
|
104330
104470
|
/*modifiers*/ undefined, factory.createImportClause(
|
|
104331
104471
|
/*isTypeOnly*/ false,
|
|
104332
104472
|
/*name*/ undefined, factory.createNamedImports([
|
|
104333
|
-
factory.createImportSpecifier(factory.createIdentifier("createRequire"), createRequireName)
|
|
104473
|
+
factory.createImportSpecifier(/*isTypeOnly*/ false, factory.createIdentifier("createRequire"), createRequireName)
|
|
104334
104474
|
])), factory.createStringLiteral("module"));
|
|
104335
104475
|
var requireHelperName = factory.createUniqueName("__require", 16 /* Optimistic */ | 32 /* FileLevel */);
|
|
104336
104476
|
var requireStatement = factory.createVariableStatement(
|
|
@@ -104370,7 +104510,7 @@ var ts;
|
|
|
104370
104510
|
if (ts.hasSyntacticModifier(node, 1 /* Export */)) {
|
|
104371
104511
|
statements = ts.append(statements, factory.createExportDeclaration(
|
|
104372
104512
|
/*decorators*/ undefined,
|
|
104373
|
-
/*modifiers*/ undefined, node.isTypeOnly, factory.createNamedExports([factory.createExportSpecifier(/*propertyName*/ undefined, ts.idText(node.name))])));
|
|
104513
|
+
/*modifiers*/ undefined, node.isTypeOnly, factory.createNamedExports([factory.createExportSpecifier(/*isTypeOnly*/ false, /*propertyName*/ undefined, ts.idText(node.name))])));
|
|
104374
104514
|
}
|
|
104375
104515
|
return statements;
|
|
104376
104516
|
}
|
|
@@ -104398,7 +104538,7 @@ var ts;
|
|
|
104398
104538
|
var exportDecl = ts.isExportNamespaceAsDefaultDeclaration(node) ? factory.createExportDefault(synthName) : factory.createExportDeclaration(
|
|
104399
104539
|
/*decorators*/ undefined,
|
|
104400
104540
|
/*modifiers*/ undefined,
|
|
104401
|
-
/*isTypeOnly*/ false, factory.createNamedExports([factory.createExportSpecifier(synthName, oldIdentifier)]));
|
|
104541
|
+
/*isTypeOnly*/ false, factory.createNamedExports([factory.createExportSpecifier(/*isTypeOnly*/ false, synthName, oldIdentifier)]));
|
|
104402
104542
|
ts.setOriginalNode(exportDecl, node);
|
|
104403
104543
|
return [importDecl, exportDecl];
|
|
104404
104544
|
}
|
|
@@ -105965,7 +106105,7 @@ var ts;
|
|
|
105965
106105
|
/*modifiers*/ undefined,
|
|
105966
106106
|
/*isTypeOnly*/ false, factory.createNamedExports(ts.map(exportMappings_1, function (_a) {
|
|
105967
106107
|
var gen = _a[0], exp = _a[1];
|
|
105968
|
-
return factory.createExportSpecifier(gen, exp);
|
|
106108
|
+
return factory.createExportSpecifier(/*isTypeOnly*/ false, gen, exp);
|
|
105969
106109
|
}))));
|
|
105970
106110
|
}
|
|
105971
106111
|
var namespaceDecl = factory.createModuleDeclaration(/*decorators*/ undefined, ensureModifiers(input), input.name, factory.createModuleBlock(declarations), 16 /* Namespace */);
|
|
@@ -109904,6 +110044,10 @@ var ts;
|
|
|
109904
110044
|
writePunctuation("}");
|
|
109905
110045
|
}
|
|
109906
110046
|
function emitImportOrExportSpecifier(node) {
|
|
110047
|
+
if (node.isTypeOnly) {
|
|
110048
|
+
writeKeyword("type");
|
|
110049
|
+
writeSpace();
|
|
110050
|
+
}
|
|
109907
110051
|
if (node.propertyName) {
|
|
109908
110052
|
emit(node.propertyName);
|
|
109909
110053
|
writeSpace();
|
|
@@ -124332,6 +124476,10 @@ var ts;
|
|
|
124332
124476
|
return node.kind === 151 /* TypeKeyword */;
|
|
124333
124477
|
}
|
|
124334
124478
|
ts.isTypeKeywordToken = isTypeKeywordToken;
|
|
124479
|
+
function isTypeKeywordTokenOrIdentifier(node) {
|
|
124480
|
+
return isTypeKeywordToken(node) || ts.isIdentifier(node) && node.text === "type";
|
|
124481
|
+
}
|
|
124482
|
+
ts.isTypeKeywordTokenOrIdentifier = isTypeKeywordTokenOrIdentifier;
|
|
124335
124483
|
/** True if the symbol is for an external module, as opposed to a namespace. */
|
|
124336
124484
|
function isExternalModuleSymbol(moduleSymbol) {
|
|
124337
124485
|
return !!(moduleSymbol.flags & 1536 /* Module */) && moduleSymbol.name.charCodeAt(0) === 34 /* doubleQuote */;
|
|
@@ -127296,7 +127444,7 @@ var ts;
|
|
|
127296
127444
|
return convertPathCompletions(completion.paths);
|
|
127297
127445
|
case 1 /* Properties */: {
|
|
127298
127446
|
var entries = [];
|
|
127299
|
-
Completions.getCompletionEntriesFromSymbols(completion.symbols, entries, contextToken, sourceFile, sourceFile, checker, 99 /* ESNext */, log, 4 /* String */, preferences, options); // Target will not be used, so arbitrary
|
|
127447
|
+
Completions.getCompletionEntriesFromSymbols(completion.symbols, entries, contextToken, contextToken, sourceFile, sourceFile, checker, 99 /* ESNext */, log, 4 /* String */, preferences, options); // Target will not be used, so arbitrary
|
|
127300
127448
|
return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: completion.hasIndexSignature, optionalReplacementSpan: optionalReplacementSpan, entries: entries };
|
|
127301
127449
|
}
|
|
127302
127450
|
case 2 /* Types */: {
|
|
@@ -128068,6 +128216,7 @@ var ts;
|
|
|
128068
128216
|
KeywordCompletionFilters[KeywordCompletionFilters["FunctionLikeBodyKeywords"] = 5] = "FunctionLikeBodyKeywords";
|
|
128069
128217
|
KeywordCompletionFilters[KeywordCompletionFilters["TypeAssertionKeywords"] = 6] = "TypeAssertionKeywords";
|
|
128070
128218
|
KeywordCompletionFilters[KeywordCompletionFilters["TypeKeywords"] = 7] = "TypeKeywords";
|
|
128219
|
+
KeywordCompletionFilters[KeywordCompletionFilters["TypeKeyword"] = 8] = "TypeKeyword";
|
|
128071
128220
|
KeywordCompletionFilters[KeywordCompletionFilters["Last"] = 7] = "Last";
|
|
128072
128221
|
})(KeywordCompletionFilters || (KeywordCompletionFilters = {}));
|
|
128073
128222
|
var GlobalsSearch;
|
|
@@ -128169,7 +128318,7 @@ var ts;
|
|
|
128169
128318
|
case 3 /* JsDocParameterName */:
|
|
128170
128319
|
return jsdocCompletionInfo(ts.JsDoc.getJSDocParameterNameCompletions(completionData.tag));
|
|
128171
128320
|
case 4 /* Keywords */:
|
|
128172
|
-
return specificKeywordCompletionInfo(completionData.
|
|
128321
|
+
return specificKeywordCompletionInfo(completionData.keywordCompletions, completionData.isNewIdentifierLocation);
|
|
128173
128322
|
default:
|
|
128174
128323
|
return ts.Debug.assertNever(completionData);
|
|
128175
128324
|
}
|
|
@@ -128220,25 +128369,41 @@ var ts;
|
|
|
128220
128369
|
function jsdocCompletionInfo(entries) {
|
|
128221
128370
|
return { isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, entries: entries };
|
|
128222
128371
|
}
|
|
128223
|
-
function
|
|
128372
|
+
function keywordToCompletionEntry(keyword) {
|
|
128373
|
+
return {
|
|
128374
|
+
name: ts.tokenToString(keyword),
|
|
128375
|
+
kind: "keyword" /* keyword */,
|
|
128376
|
+
kindModifiers: "" /* none */,
|
|
128377
|
+
sortText: SortText.GlobalsOrKeywords,
|
|
128378
|
+
};
|
|
128379
|
+
}
|
|
128380
|
+
function specificKeywordCompletionInfo(entries, isNewIdentifierLocation) {
|
|
128224
128381
|
return {
|
|
128225
128382
|
isGlobalCompletion: false,
|
|
128226
128383
|
isMemberCompletion: false,
|
|
128227
|
-
isNewIdentifierLocation:
|
|
128228
|
-
entries:
|
|
128229
|
-
name: ts.tokenToString(k),
|
|
128230
|
-
kind: "keyword" /* keyword */,
|
|
128231
|
-
kindModifiers: "" /* none */,
|
|
128232
|
-
sortText: SortText.GlobalsOrKeywords,
|
|
128233
|
-
}); }),
|
|
128384
|
+
isNewIdentifierLocation: isNewIdentifierLocation,
|
|
128385
|
+
entries: entries.slice(),
|
|
128234
128386
|
};
|
|
128235
128387
|
}
|
|
128388
|
+
function keywordCompletionData(keywordFilters, filterOutTsOnlyKeywords, isNewIdentifierLocation) {
|
|
128389
|
+
return {
|
|
128390
|
+
kind: 4 /* Keywords */,
|
|
128391
|
+
keywordCompletions: getKeywordCompletions(keywordFilters, filterOutTsOnlyKeywords),
|
|
128392
|
+
isNewIdentifierLocation: isNewIdentifierLocation,
|
|
128393
|
+
};
|
|
128394
|
+
}
|
|
128395
|
+
function keywordFiltersFromSyntaxKind(keywordCompletion) {
|
|
128396
|
+
switch (keywordCompletion) {
|
|
128397
|
+
case 151 /* TypeKeyword */: return 8 /* TypeKeyword */;
|
|
128398
|
+
default: ts.Debug.fail("Unknown mapping from SyntaxKind to KeywordCompletionFilters");
|
|
128399
|
+
}
|
|
128400
|
+
}
|
|
128236
128401
|
function getOptionalReplacementSpan(location) {
|
|
128237
128402
|
// StringLiteralLike locations are handled separately in stringCompletions.ts
|
|
128238
128403
|
return (location === null || location === void 0 ? void 0 : location.kind) === 79 /* Identifier */ ? ts.createTextSpanFromNode(location) : undefined;
|
|
128239
128404
|
}
|
|
128240
128405
|
function completionInfoFromData(sourceFile, typeChecker, compilerOptions, log, completionData, preferences) {
|
|
128241
|
-
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;
|
|
128406
|
+
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;
|
|
128242
128407
|
// Verify if the file is JSX language variant
|
|
128243
128408
|
if (ts.getLanguageVariant(sourceFile.scriptKind) === 1 /* JSX */) {
|
|
128244
128409
|
var completionInfo = getJsxClosingTagCompletion(location, sourceFile);
|
|
@@ -128249,7 +128414,7 @@ var ts;
|
|
|
128249
128414
|
var entries = [];
|
|
128250
128415
|
if (isUncheckedFile(sourceFile, compilerOptions)) {
|
|
128251
128416
|
var uniqueNames = getCompletionEntriesFromSymbols(symbols, entries,
|
|
128252
|
-
/*
|
|
128417
|
+
/*replacementToken*/ undefined, contextToken, location, sourceFile, typeChecker, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
|
|
128253
128418
|
getJSCompletionEntries(sourceFile, location.pos, uniqueNames, ts.getEmitScriptTarget(compilerOptions), entries); // TODO: GH#18217
|
|
128254
128419
|
}
|
|
128255
128420
|
else {
|
|
@@ -128257,7 +128422,7 @@ var ts;
|
|
|
128257
128422
|
return undefined;
|
|
128258
128423
|
}
|
|
128259
128424
|
getCompletionEntriesFromSymbols(symbols, entries,
|
|
128260
|
-
/*
|
|
128425
|
+
/*replacementToken*/ undefined, contextToken, location, sourceFile, typeChecker, ts.getEmitScriptTarget(compilerOptions), log, completionKind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, isJsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap);
|
|
128261
128426
|
}
|
|
128262
128427
|
if (keywordFilters !== 0 /* None */) {
|
|
128263
128428
|
var entryNames = new ts.Set(entries.map(function (e) { return e.name; }));
|
|
@@ -128363,10 +128528,10 @@ var ts;
|
|
|
128363
128528
|
function createCompletionEntryForLiteral(sourceFile, preferences, literal) {
|
|
128364
128529
|
return { name: completionNameForLiteral(sourceFile, preferences, literal), kind: "string" /* string */, kindModifiers: "" /* none */, sortText: SortText.LocationPriority };
|
|
128365
128530
|
}
|
|
128366
|
-
function createCompletionEntry(symbol, sortText, contextToken, location, sourceFile, typeChecker, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode,
|
|
128531
|
+
function createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, typeChecker, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, options, preferences) {
|
|
128367
128532
|
var _a;
|
|
128368
128533
|
var insertText;
|
|
128369
|
-
var replacementSpan = ts.getReplacementSpanForContextToken(
|
|
128534
|
+
var replacementSpan = ts.getReplacementSpanForContextToken(replacementToken);
|
|
128370
128535
|
var data;
|
|
128371
128536
|
var isSnippet;
|
|
128372
128537
|
var sourceDisplay;
|
|
@@ -128417,7 +128582,7 @@ var ts;
|
|
|
128417
128582
|
if (originIsResolvedExport(origin)) {
|
|
128418
128583
|
sourceDisplay = [ts.textPart(origin.moduleSpecifier)];
|
|
128419
128584
|
if (importCompletionNode) {
|
|
128420
|
-
(_a = getInsertTextAndReplacementSpanForImportCompletion(name, importCompletionNode,
|
|
128585
|
+
(_a = getInsertTextAndReplacementSpanForImportCompletion(name, importCompletionNode, contextToken, origin, useSemicolons, options, preferences), insertText = _a.insertText, replacementSpan = _a.replacementSpan);
|
|
128421
128586
|
isSnippet = preferences.includeCompletionsWithSnippetText ? true : undefined;
|
|
128422
128587
|
}
|
|
128423
128588
|
}
|
|
@@ -128490,22 +128655,26 @@ var ts;
|
|
|
128490
128655
|
moduleSpecifier: originIsResolvedExport(origin) ? origin.moduleSpecifier : undefined,
|
|
128491
128656
|
};
|
|
128492
128657
|
}
|
|
128493
|
-
function getInsertTextAndReplacementSpanForImportCompletion(name, importCompletionNode,
|
|
128658
|
+
function getInsertTextAndReplacementSpanForImportCompletion(name, importCompletionNode, contextToken, origin, useSemicolons, options, preferences) {
|
|
128659
|
+
var _a, _b, _c;
|
|
128494
128660
|
var sourceFile = importCompletionNode.getSourceFile();
|
|
128495
|
-
var replacementSpan = ts.createTextSpanFromNode(importCompletionNode, sourceFile);
|
|
128661
|
+
var replacementSpan = ts.createTextSpanFromNode(ts.findAncestor(importCompletionNode, ts.or(ts.isImportDeclaration, ts.isImportEqualsDeclaration)) || importCompletionNode, sourceFile);
|
|
128496
128662
|
var quotedModuleSpecifier = ts.quote(sourceFile, preferences, origin.moduleSpecifier);
|
|
128497
128663
|
var exportKind = origin.isDefaultExport ? 1 /* Default */ :
|
|
128498
128664
|
origin.exportName === "export=" /* ExportEquals */ ? 2 /* ExportEquals */ :
|
|
128499
128665
|
0 /* Named */;
|
|
128500
128666
|
var tabStop = preferences.includeCompletionsWithSnippetText ? "$1" : "";
|
|
128501
128667
|
var importKind = ts.codefix.getImportKind(sourceFile, exportKind, options, /*forceImportKeyword*/ true);
|
|
128502
|
-
var
|
|
128668
|
+
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);
|
|
128669
|
+
var isImportSpecifierTypeOnly = couldBeTypeOnlyImportSpecifier(importCompletionNode, contextToken);
|
|
128670
|
+
var topLevelTypeOnlyText = isTopLevelTypeOnly ? " " + ts.tokenToString(151 /* TypeKeyword */) + " " : " ";
|
|
128671
|
+
var importSpecifierTypeOnlyText = isImportSpecifierTypeOnly ? ts.tokenToString(151 /* TypeKeyword */) + " " : "";
|
|
128503
128672
|
var suffix = useSemicolons ? ";" : "";
|
|
128504
128673
|
switch (importKind) {
|
|
128505
|
-
case 3 /* CommonJS */: return { replacementSpan: replacementSpan, insertText: "import" +
|
|
128506
|
-
case 1 /* Default */: return { replacementSpan: replacementSpan, insertText: "import" +
|
|
128507
|
-
case 2 /* Namespace */: return { replacementSpan: replacementSpan, insertText: "import" +
|
|
128508
|
-
case 0 /* Named */: return { replacementSpan: replacementSpan, insertText: "import" +
|
|
128674
|
+
case 3 /* CommonJS */: return { replacementSpan: replacementSpan, insertText: "import" + topLevelTypeOnlyText + escapeSnippetText(name) + tabStop + " = require(" + quotedModuleSpecifier + ")" + suffix };
|
|
128675
|
+
case 1 /* Default */: return { replacementSpan: replacementSpan, insertText: "import" + topLevelTypeOnlyText + escapeSnippetText(name) + tabStop + " from " + quotedModuleSpecifier + suffix };
|
|
128676
|
+
case 2 /* Namespace */: return { replacementSpan: replacementSpan, insertText: "import" + topLevelTypeOnlyText + "* as " + escapeSnippetText(name) + " from " + quotedModuleSpecifier + suffix };
|
|
128677
|
+
case 0 /* Named */: return { replacementSpan: replacementSpan, insertText: "import" + topLevelTypeOnlyText + "{ " + importSpecifierTypeOnlyText + escapeSnippetText(name) + tabStop + " } from " + quotedModuleSpecifier + suffix };
|
|
128509
128678
|
}
|
|
128510
128679
|
}
|
|
128511
128680
|
function quotePropertyName(sourceFile, preferences, name) {
|
|
@@ -128529,12 +128698,11 @@ var ts;
|
|
|
128529
128698
|
return CompletionSource.ThisProperty;
|
|
128530
128699
|
}
|
|
128531
128700
|
}
|
|
128532
|
-
function getCompletionEntriesFromSymbols(symbols, entries, contextToken, location, sourceFile, typeChecker, target, log, kind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap) {
|
|
128701
|
+
function getCompletionEntriesFromSymbols(symbols, entries, replacementToken, contextToken, location, sourceFile, typeChecker, target, log, kind, preferences, compilerOptions, isTypeOnlyLocation, propertyAccessToConvert, jsxIdentifierExpected, isJsxInitializer, importCompletionNode, recommendedCompletion, symbolToOriginInfoMap, symbolToSortTextIdMap) {
|
|
128533
128702
|
var _a;
|
|
128534
128703
|
var start = ts.timestamp();
|
|
128535
128704
|
var variableDeclaration = getVariableDeclaration(location);
|
|
128536
128705
|
var useSemicolons = ts.probablyUsesSemicolons(sourceFile);
|
|
128537
|
-
var isTypeOnlyImport = !!importCompletionNode && ts.isTypeOnlyImportOrExportDeclaration(location.parent);
|
|
128538
128706
|
// Tracks unique names.
|
|
128539
128707
|
// Value is set to false for global variables or completions from external module exports, because we can have multiple of those;
|
|
128540
128708
|
// true otherwise. Based on the order we add things we will always see locals first, then globals, then module exports.
|
|
@@ -128550,7 +128718,7 @@ var ts;
|
|
|
128550
128718
|
var name = info.name, needsConvertPropertyAccess = info.needsConvertPropertyAccess;
|
|
128551
128719
|
var sortTextId = (_a = symbolToSortTextIdMap === null || symbolToSortTextIdMap === void 0 ? void 0 : symbolToSortTextIdMap[ts.getSymbolId(symbol)]) !== null && _a !== void 0 ? _a : 11 /* LocationPriority */;
|
|
128552
128720
|
var sortText = (isDeprecated(symbol, typeChecker) ? 8 /* DeprecatedOffset */ + sortTextId : sortTextId).toString();
|
|
128553
|
-
var entry = createCompletionEntry(symbol, sortText, contextToken, location, sourceFile, typeChecker, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode,
|
|
128721
|
+
var entry = createCompletionEntry(symbol, sortText, replacementToken, contextToken, location, sourceFile, typeChecker, name, needsConvertPropertyAccess, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, importCompletionNode, useSemicolons, compilerOptions, preferences);
|
|
128554
128722
|
if (!entry) {
|
|
128555
128723
|
continue;
|
|
128556
128724
|
}
|
|
@@ -128699,7 +128867,7 @@ var ts;
|
|
|
128699
128867
|
case 3 /* JsDocParameterName */:
|
|
128700
128868
|
return ts.JsDoc.getJSDocParameterNameCompletionDetails(name);
|
|
128701
128869
|
case 4 /* Keywords */:
|
|
128702
|
-
return
|
|
128870
|
+
return ts.some(request.keywordCompletions, function (c) { return c.name === name; }) ? createSimpleDetails(name, "keyword" /* keyword */, ts.SymbolDisplayPartKind.keyword) : undefined;
|
|
128703
128871
|
default:
|
|
128704
128872
|
return ts.Debug.assertNever(request);
|
|
128705
128873
|
}
|
|
@@ -128738,7 +128906,7 @@ var ts;
|
|
|
128738
128906
|
function getCompletionEntryCodeActionsAndSourceDisplay(origin, symbol, program, host, compilerOptions, sourceFile, position, previousToken, formatContext, preferences, data) {
|
|
128739
128907
|
if (data === null || data === void 0 ? void 0 : data.moduleSpecifier) {
|
|
128740
128908
|
var _a = getRelevantTokens(position, sourceFile), contextToken = _a.contextToken, previousToken_1 = _a.previousToken;
|
|
128741
|
-
if (previousToken_1 &&
|
|
128909
|
+
if (previousToken_1 && getImportStatementCompletionInfo(contextToken || previousToken_1).replacementNode) {
|
|
128742
128910
|
// Import statement completion: 'import c|'
|
|
128743
128911
|
return { codeActions: undefined, sourceDisplay: [ts.textPart(data.moduleSpecifier)] };
|
|
128744
128912
|
}
|
|
@@ -128901,6 +129069,7 @@ var ts;
|
|
|
128901
129069
|
start = ts.timestamp();
|
|
128902
129070
|
// The decision to provide completion depends on the contextToken, which is determined through the previousToken.
|
|
128903
129071
|
// Note: 'previousToken' (and thus 'contextToken') can be undefined if we are the beginning of the file
|
|
129072
|
+
var isJsOnlyLocation = !insideJsDocTagTypeExpression && ts.isSourceFileJS(sourceFile);
|
|
128904
129073
|
var tokens = getRelevantTokens(position, sourceFile);
|
|
128905
129074
|
var previousToken = tokens.previousToken;
|
|
128906
129075
|
var contextToken = tokens.contextToken;
|
|
@@ -128918,22 +129087,34 @@ var ts;
|
|
|
128918
129087
|
var isJsxIdentifierExpected = false;
|
|
128919
129088
|
var importCompletionNode;
|
|
128920
129089
|
var location = ts.getTouchingPropertyName(sourceFile, position);
|
|
129090
|
+
var keywordFilters = 0 /* None */;
|
|
129091
|
+
var isNewIdentifierLocation = false;
|
|
128921
129092
|
if (contextToken) {
|
|
128922
|
-
var
|
|
128923
|
-
|
|
128924
|
-
|
|
129093
|
+
var importStatementCompletion = getImportStatementCompletionInfo(contextToken);
|
|
129094
|
+
isNewIdentifierLocation = importStatementCompletion.isNewIdentifierLocation;
|
|
129095
|
+
if (importStatementCompletion.keywordCompletion) {
|
|
129096
|
+
if (importStatementCompletion.isKeywordOnlyCompletion) {
|
|
129097
|
+
return {
|
|
129098
|
+
kind: 4 /* Keywords */,
|
|
129099
|
+
keywordCompletions: [keywordToCompletionEntry(importStatementCompletion.keywordCompletion)],
|
|
129100
|
+
isNewIdentifierLocation: isNewIdentifierLocation,
|
|
129101
|
+
};
|
|
129102
|
+
}
|
|
129103
|
+
keywordFilters = keywordFiltersFromSyntaxKind(importStatementCompletion.keywordCompletion);
|
|
128925
129104
|
}
|
|
128926
|
-
|
|
128927
|
-
|
|
128928
|
-
|
|
128929
|
-
|
|
128930
|
-
|
|
128931
|
-
importCompletionNode =
|
|
129105
|
+
if (importStatementCompletion.replacementNode && preferences.includeCompletionsForImportStatements && preferences.includeCompletionsWithInsertText) {
|
|
129106
|
+
// Import statement completions use `insertText`, and also require the `data` property of `CompletionEntryIdentifier`
|
|
129107
|
+
// added in TypeScript 4.3 to be sent back from the client during `getCompletionEntryDetails`. Since this feature
|
|
129108
|
+
// is not backward compatible with older clients, the language service defaults to disabling it, allowing newer clients
|
|
129109
|
+
// to opt in with the `includeCompletionsForImportStatements` user preference.
|
|
129110
|
+
importCompletionNode = importStatementCompletion.replacementNode;
|
|
128932
129111
|
}
|
|
128933
129112
|
// Bail out if this is a known invalid completion location
|
|
128934
129113
|
if (!importCompletionNode && isCompletionListBlocker(contextToken)) {
|
|
128935
129114
|
log("Returning an empty list because completion was requested in an invalid position.");
|
|
128936
|
-
return
|
|
129115
|
+
return keywordFilters
|
|
129116
|
+
? keywordCompletionData(keywordFilters, isJsOnlyLocation, isNewIdentifierDefinitionLocation())
|
|
129117
|
+
: undefined;
|
|
128937
129118
|
}
|
|
128938
129119
|
var parent = contextToken.parent;
|
|
128939
129120
|
if (contextToken.kind === 24 /* DotToken */ || contextToken.kind === 28 /* QuestionDotToken */) {
|
|
@@ -129053,10 +129234,8 @@ var ts;
|
|
|
129053
129234
|
}
|
|
129054
129235
|
var semanticStart = ts.timestamp();
|
|
129055
129236
|
var completionKind = 5 /* None */;
|
|
129056
|
-
var isNewIdentifierLocation = false;
|
|
129057
129237
|
var isNonContextualObjectLiteral = false;
|
|
129058
129238
|
var hasUnresolvedAutoImports = false;
|
|
129059
|
-
var keywordFilters = 0 /* None */;
|
|
129060
129239
|
// This also gets mutated in nested-functions after the return
|
|
129061
129240
|
var symbols = [];
|
|
129062
129241
|
var symbolToOriginInfoMap = [];
|
|
@@ -129090,7 +129269,9 @@ var ts;
|
|
|
129090
129269
|
// global symbols in scope. These results should be valid for either language as
|
|
129091
129270
|
// the set of symbols that can be referenced from this location.
|
|
129092
129271
|
if (!tryGetGlobalSymbols()) {
|
|
129093
|
-
return
|
|
129272
|
+
return keywordFilters
|
|
129273
|
+
? keywordCompletionData(keywordFilters, isJsOnlyLocation, isNewIdentifierLocation)
|
|
129274
|
+
: undefined;
|
|
129094
129275
|
}
|
|
129095
129276
|
}
|
|
129096
129277
|
log("getCompletionData: Semantic work: " + (ts.timestamp() - semanticStart));
|
|
@@ -129110,6 +129291,7 @@ var ts;
|
|
|
129110
129291
|
symbolToOriginInfoMap: symbolToOriginInfoMap,
|
|
129111
129292
|
recommendedCompletion: recommendedCompletion,
|
|
129112
129293
|
previousToken: previousToken,
|
|
129294
|
+
contextToken: contextToken,
|
|
129113
129295
|
isJsxInitializer: isJsxInitializer,
|
|
129114
129296
|
insideJsDocTagTypeExpression: insideJsDocTagTypeExpression,
|
|
129115
129297
|
symbolToSortTextIdMap: symbolToSortTextIdMap,
|
|
@@ -129496,8 +129678,14 @@ var ts;
|
|
|
129496
129678
|
// Asking for completion details for an item that is not an auto-import
|
|
129497
129679
|
return;
|
|
129498
129680
|
}
|
|
129681
|
+
// import { type | -> token text should be blank
|
|
129682
|
+
var isAfterTypeOnlyImportSpecifierModifier = previousToken === contextToken
|
|
129683
|
+
&& importCompletionNode
|
|
129684
|
+
&& couldBeTypeOnlyImportSpecifier(importCompletionNode, contextToken);
|
|
129685
|
+
var lowerCaseTokenText = isAfterTypeOnlyImportSpecifierModifier ? "" :
|
|
129686
|
+
previousToken && ts.isIdentifier(previousToken) ? previousToken.text.toLowerCase() :
|
|
129687
|
+
"";
|
|
129499
129688
|
var moduleSpecifierCache = (_a = host.getModuleSpecifierCache) === null || _a === void 0 ? void 0 : _a.call(host);
|
|
129500
|
-
var lowerCaseTokenText = previousToken && ts.isIdentifier(previousToken) ? previousToken.text.toLowerCase() : "";
|
|
129501
129689
|
var exportInfo = ts.getExportInfoMap(sourceFile, host, program, cancellationToken);
|
|
129502
129690
|
var packageJsonAutoImportProvider = (_b = host.getPackageJsonAutoImportProvider) === null || _b === void 0 ? void 0 : _b.call(host);
|
|
129503
129691
|
var packageJsonFilter = detailsEntryId ? undefined : ts.createPackageJsonImportFilter(sourceFile, preferences, host);
|
|
@@ -129630,6 +129818,7 @@ var ts;
|
|
|
129630
129818
|
|| containingNodeKind === 161 /* ComputedPropertyName */; // [ | /* this can become an index signature */
|
|
129631
129819
|
case 141 /* ModuleKeyword */: // module |
|
|
129632
129820
|
case 142 /* NamespaceKeyword */: // namespace |
|
|
129821
|
+
case 100 /* ImportKeyword */: // import |
|
|
129633
129822
|
return true;
|
|
129634
129823
|
case 24 /* DotToken */:
|
|
129635
129824
|
return containingNodeKind === 260 /* ModuleDeclaration */; // module A.|
|
|
@@ -129768,23 +129957,38 @@ var ts;
|
|
|
129768
129957
|
* Relevant symbols are stored in the captured 'symbols' variable.
|
|
129769
129958
|
*/
|
|
129770
129959
|
function tryGetImportOrExportClauseCompletionSymbols() {
|
|
129771
|
-
|
|
129772
|
-
|
|
129773
|
-
|
|
129960
|
+
if (!contextToken)
|
|
129961
|
+
return 0 /* Continue */;
|
|
129962
|
+
// `import { |` or `import { a as 0, | }` or `import { type | }`
|
|
129963
|
+
var namedImportsOrExports = contextToken.kind === 18 /* OpenBraceToken */ || contextToken.kind === 27 /* CommaToken */ ? ts.tryCast(contextToken.parent, ts.isNamedImportsOrExports) :
|
|
129964
|
+
ts.isTypeKeywordTokenOrIdentifier(contextToken) ? ts.tryCast(contextToken.parent.parent, ts.isNamedImportsOrExports) : undefined;
|
|
129774
129965
|
if (!namedImportsOrExports)
|
|
129775
129966
|
return 0 /* Continue */;
|
|
129967
|
+
// We can at least offer `type` at `import { |`
|
|
129968
|
+
if (!ts.isTypeKeywordTokenOrIdentifier(contextToken)) {
|
|
129969
|
+
keywordFilters = 8 /* TypeKeyword */;
|
|
129970
|
+
}
|
|
129776
129971
|
// try to show exported member for imported/re-exported module
|
|
129777
129972
|
var moduleSpecifier = (namedImportsOrExports.kind === 268 /* NamedImports */ ? namedImportsOrExports.parent.parent : namedImportsOrExports.parent).moduleSpecifier;
|
|
129778
|
-
if (!moduleSpecifier)
|
|
129973
|
+
if (!moduleSpecifier) {
|
|
129974
|
+
isNewIdentifierLocation = true;
|
|
129779
129975
|
return namedImportsOrExports.kind === 268 /* NamedImports */ ? 2 /* Fail */ : 0 /* Continue */;
|
|
129976
|
+
}
|
|
129780
129977
|
var moduleSpecifierSymbol = typeChecker.getSymbolAtLocation(moduleSpecifier); // TODO: GH#18217
|
|
129781
|
-
if (!moduleSpecifierSymbol)
|
|
129978
|
+
if (!moduleSpecifierSymbol) {
|
|
129979
|
+
isNewIdentifierLocation = true;
|
|
129782
129980
|
return 2 /* Fail */;
|
|
129981
|
+
}
|
|
129783
129982
|
completionKind = 3 /* MemberLike */;
|
|
129784
129983
|
isNewIdentifierLocation = false;
|
|
129785
129984
|
var exports = typeChecker.getExportsAndPropertiesOfModule(moduleSpecifierSymbol);
|
|
129786
129985
|
var existing = new ts.Set(namedImportsOrExports.elements.filter(function (n) { return !isCurrentlyEditingNode(n); }).map(function (n) { return (n.propertyName || n.name).escapedText; }));
|
|
129787
|
-
|
|
129986
|
+
var uniques = exports.filter(function (e) { return e.escapedName !== "default" /* Default */ && !existing.has(e.escapedName); });
|
|
129987
|
+
symbols = ts.concatenate(symbols, uniques);
|
|
129988
|
+
if (!uniques.length) {
|
|
129989
|
+
// If there's nothing else to import, don't offer `type` either
|
|
129990
|
+
keywordFilters = 0 /* None */;
|
|
129991
|
+
}
|
|
129788
129992
|
return 1 /* Success */;
|
|
129789
129993
|
}
|
|
129790
129994
|
/**
|
|
@@ -130045,6 +130249,14 @@ var ts;
|
|
|
130045
130249
|
case 136 /* GetKeyword */:
|
|
130046
130250
|
case 148 /* SetKeyword */:
|
|
130047
130251
|
return !isFromObjectTypeDeclaration(contextToken);
|
|
130252
|
+
case 79 /* Identifier */:
|
|
130253
|
+
if (containingNodeKind === 269 /* ImportSpecifier */ &&
|
|
130254
|
+
contextToken === parent.name &&
|
|
130255
|
+
contextToken.text === "type") {
|
|
130256
|
+
// import { type | }
|
|
130257
|
+
return false;
|
|
130258
|
+
}
|
|
130259
|
+
break;
|
|
130048
130260
|
case 84 /* ClassKeyword */:
|
|
130049
130261
|
case 92 /* EnumKeyword */:
|
|
130050
130262
|
case 118 /* InterfaceKeyword */:
|
|
@@ -130054,8 +130266,10 @@ var ts;
|
|
|
130054
130266
|
case 119 /* LetKeyword */:
|
|
130055
130267
|
case 85 /* ConstKeyword */:
|
|
130056
130268
|
case 137 /* InferKeyword */:
|
|
130057
|
-
case 151 /* TypeKeyword */: // type htm|
|
|
130058
130269
|
return true;
|
|
130270
|
+
case 151 /* TypeKeyword */:
|
|
130271
|
+
// import { type foo| }
|
|
130272
|
+
return containingNodeKind !== 269 /* ImportSpecifier */;
|
|
130059
130273
|
case 41 /* AsteriskToken */:
|
|
130060
130274
|
return ts.isFunctionLike(contextToken.parent) && !ts.isMethodDeclaration(contextToken.parent);
|
|
130061
130275
|
}
|
|
@@ -130416,6 +130630,8 @@ var ts;
|
|
|
130416
130630
|
return ts.isTypeKeyword(kind) || kind === 85 /* ConstKeyword */;
|
|
130417
130631
|
case 7 /* TypeKeywords */:
|
|
130418
130632
|
return ts.isTypeKeyword(kind);
|
|
130633
|
+
case 8 /* TypeKeyword */:
|
|
130634
|
+
return kind === 151 /* TypeKeyword */;
|
|
130419
130635
|
default:
|
|
130420
130636
|
return ts.Debug.assertNever(keywordFilter);
|
|
130421
130637
|
}
|
|
@@ -130689,34 +130905,67 @@ var ts;
|
|
|
130689
130905
|
}
|
|
130690
130906
|
return undefined;
|
|
130691
130907
|
}
|
|
130692
|
-
function
|
|
130908
|
+
function getImportStatementCompletionInfo(contextToken) {
|
|
130909
|
+
var keywordCompletion;
|
|
130910
|
+
var isKeywordOnlyCompletion = false;
|
|
130693
130911
|
var candidate = getCandidate();
|
|
130694
|
-
return
|
|
130912
|
+
return {
|
|
130913
|
+
isKeywordOnlyCompletion: isKeywordOnlyCompletion,
|
|
130914
|
+
keywordCompletion: keywordCompletion,
|
|
130915
|
+
isNewIdentifierLocation: !!(candidate || keywordCompletion === 151 /* TypeKeyword */),
|
|
130916
|
+
replacementNode: candidate && ts.rangeIsOnSingleLine(candidate, candidate.getSourceFile())
|
|
130917
|
+
? candidate
|
|
130918
|
+
: undefined
|
|
130919
|
+
};
|
|
130695
130920
|
function getCandidate() {
|
|
130696
130921
|
var parent = contextToken.parent;
|
|
130697
130922
|
if (ts.isImportEqualsDeclaration(parent)) {
|
|
130923
|
+
keywordCompletion = contextToken.kind === 151 /* TypeKeyword */ ? undefined : 151 /* TypeKeyword */;
|
|
130698
130924
|
return isModuleSpecifierMissingOrEmpty(parent.moduleReference) ? parent : undefined;
|
|
130699
130925
|
}
|
|
130926
|
+
if (couldBeTypeOnlyImportSpecifier(parent, contextToken) && canCompleteFromNamedBindings(parent.parent)) {
|
|
130927
|
+
return parent;
|
|
130928
|
+
}
|
|
130700
130929
|
if (ts.isNamedImports(parent) || ts.isNamespaceImport(parent)) {
|
|
130701
|
-
if (
|
|
130930
|
+
if (!parent.parent.isTypeOnly && (contextToken.kind === 18 /* OpenBraceToken */ ||
|
|
130931
|
+
contextToken.kind === 100 /* ImportKeyword */ ||
|
|
130932
|
+
contextToken.kind === 27 /* CommaToken */)) {
|
|
130933
|
+
keywordCompletion = 151 /* TypeKeyword */;
|
|
130934
|
+
}
|
|
130935
|
+
if (canCompleteFromNamedBindings(parent)) {
|
|
130702
130936
|
// At `import { ... } |` or `import * as Foo |`, the only possible completion is `from`
|
|
130703
|
-
|
|
130704
|
-
|
|
130705
|
-
|
|
130937
|
+
if (contextToken.kind === 19 /* CloseBraceToken */ || contextToken.kind === 79 /* Identifier */) {
|
|
130938
|
+
isKeywordOnlyCompletion = true;
|
|
130939
|
+
keywordCompletion = 155 /* FromKeyword */;
|
|
130940
|
+
}
|
|
130941
|
+
else {
|
|
130942
|
+
return parent.parent.parent;
|
|
130943
|
+
}
|
|
130706
130944
|
}
|
|
130707
130945
|
return undefined;
|
|
130708
130946
|
}
|
|
130709
130947
|
if (ts.isImportKeyword(contextToken) && ts.isSourceFile(parent)) {
|
|
130710
130948
|
// A lone import keyword with nothing following it does not parse as a statement at all
|
|
130949
|
+
keywordCompletion = 151 /* TypeKeyword */;
|
|
130711
130950
|
return contextToken;
|
|
130712
130951
|
}
|
|
130713
130952
|
if (ts.isImportKeyword(contextToken) && ts.isImportDeclaration(parent)) {
|
|
130714
130953
|
// `import s| from`
|
|
130954
|
+
keywordCompletion = 151 /* TypeKeyword */;
|
|
130715
130955
|
return isModuleSpecifierMissingOrEmpty(parent.moduleSpecifier) ? parent : undefined;
|
|
130716
130956
|
}
|
|
130717
130957
|
return undefined;
|
|
130718
130958
|
}
|
|
130719
130959
|
}
|
|
130960
|
+
function couldBeTypeOnlyImportSpecifier(importSpecifier, contextToken) {
|
|
130961
|
+
return ts.isImportSpecifier(importSpecifier)
|
|
130962
|
+
&& (importSpecifier.isTypeOnly || contextToken === importSpecifier.name && ts.isTypeKeywordTokenOrIdentifier(contextToken));
|
|
130963
|
+
}
|
|
130964
|
+
function canCompleteFromNamedBindings(namedBindings) {
|
|
130965
|
+
return isModuleSpecifierMissingOrEmpty(namedBindings.parent.parent.moduleSpecifier)
|
|
130966
|
+
&& (ts.isNamespaceImport(namedBindings) || namedBindings.elements.length < 2)
|
|
130967
|
+
&& !namedBindings.parent.name;
|
|
130968
|
+
}
|
|
130720
130969
|
function isModuleSpecifierMissingOrEmpty(specifier) {
|
|
130721
130970
|
var _a;
|
|
130722
130971
|
if (ts.nodeIsMissing(specifier))
|
|
@@ -136856,7 +137105,7 @@ var ts;
|
|
|
136856
137105
|
else {
|
|
136857
137106
|
for (var _e = 0, defaultImports_1 = defaultImports; _e < defaultImports_1.length; _e++) {
|
|
136858
137107
|
var defaultImport = defaultImports_1[_e];
|
|
136859
|
-
newImportSpecifiers.push(ts.factory.createImportSpecifier(ts.factory.createIdentifier("default"), defaultImport.importClause.name)); // TODO: GH#18217
|
|
137108
|
+
newImportSpecifiers.push(ts.factory.createImportSpecifier(/*isTypeOnly*/ false, ts.factory.createIdentifier("default"), defaultImport.importClause.name)); // TODO: GH#18217
|
|
136860
137109
|
}
|
|
136861
137110
|
}
|
|
136862
137111
|
newImportSpecifiers.push.apply(newImportSpecifiers, ts.flatMap(namedImports, function (i) { return i.importClause.namedBindings.elements; })); // TODO: GH#18217
|
|
@@ -136990,7 +137239,8 @@ var ts;
|
|
|
136990
137239
|
return ts.stableSort(specifiers, compareImportOrExportSpecifiers);
|
|
136991
137240
|
}
|
|
136992
137241
|
function compareImportOrExportSpecifiers(s1, s2) {
|
|
136993
|
-
return
|
|
137242
|
+
return ts.compareBooleans(s1.isTypeOnly, s2.isTypeOnly)
|
|
137243
|
+
|| compareIdentifiers(s1.propertyName || s1.name, s2.propertyName || s2.name)
|
|
136994
137244
|
|| compareIdentifiers(s1.name, s2.name);
|
|
136995
137245
|
}
|
|
136996
137246
|
OrganizeImports.compareImportOrExportSpecifiers = compareImportOrExportSpecifiers;
|
|
@@ -147148,7 +147398,7 @@ var ts;
|
|
|
147148
147398
|
*/
|
|
147149
147399
|
var newNodes = [
|
|
147150
147400
|
makeConst(/*modifiers*/ undefined, rename, assignment.right),
|
|
147151
|
-
makeExportDeclaration([ts.factory.createExportSpecifier(rename, text)]),
|
|
147401
|
+
makeExportDeclaration([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, rename, text)]),
|
|
147152
147402
|
];
|
|
147153
147403
|
changes.replaceNodeWithNodes(sourceFile, assignment.parent, newNodes);
|
|
147154
147404
|
}
|
|
@@ -147170,7 +147420,7 @@ var ts;
|
|
|
147170
147420
|
return makeExportDeclaration(/*exportClause*/ undefined, moduleSpecifier);
|
|
147171
147421
|
}
|
|
147172
147422
|
function reExportDefault(moduleSpecifier) {
|
|
147173
|
-
return makeExportDeclaration([ts.factory.createExportSpecifier(/*propertyName*/ undefined, "default")], moduleSpecifier);
|
|
147423
|
+
return makeExportDeclaration([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, /*propertyName*/ undefined, "default")], moduleSpecifier);
|
|
147174
147424
|
}
|
|
147175
147425
|
function convertExportsPropertyAssignment(_a, sourceFile, changes) {
|
|
147176
147426
|
var left = _a.left, right = _a.right, parent = _a.parent;
|
|
@@ -147312,7 +147562,7 @@ var ts;
|
|
|
147312
147562
|
}
|
|
147313
147563
|
var namedBindings = namedBindingsNames.size === 0 ? undefined : ts.arrayFrom(ts.mapIterator(namedBindingsNames.entries(), function (_a) {
|
|
147314
147564
|
var propertyName = _a[0], idName = _a[1];
|
|
147315
|
-
return ts.factory.createImportSpecifier(propertyName === idName ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(idName));
|
|
147565
|
+
return ts.factory.createImportSpecifier(/*isTypeOnly*/ false, propertyName === idName ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(idName));
|
|
147316
147566
|
}));
|
|
147317
147567
|
if (!namedBindings) {
|
|
147318
147568
|
// If it was unused, ensure that we at least import *something*.
|
|
@@ -147370,7 +147620,7 @@ var ts;
|
|
|
147370
147620
|
: ts.makeImport(/*name*/ undefined, [makeImportSpecifier(propertyName, localName)], moduleSpecifier, quotePreference);
|
|
147371
147621
|
}
|
|
147372
147622
|
function makeImportSpecifier(propertyName, name) {
|
|
147373
|
-
return ts.factory.createImportSpecifier(propertyName !== undefined && propertyName !== name ? ts.factory.createIdentifier(propertyName) : undefined, ts.factory.createIdentifier(name));
|
|
147623
|
+
return ts.factory.createImportSpecifier(/*isTypeOnly*/ false, propertyName !== undefined && propertyName !== name ? ts.factory.createIdentifier(propertyName) : undefined, ts.factory.createIdentifier(name));
|
|
147374
147624
|
}
|
|
147375
147625
|
function makeConst(modifiers, name, init) {
|
|
147376
147626
|
return ts.factory.createVariableStatement(modifiers, ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration(name, /*exclamationToken*/ undefined, /*type*/ undefined, init)], 2 /* Const */));
|
|
@@ -147695,13 +147945,13 @@ var ts;
|
|
|
147695
147945
|
codefix.registerCodeFix({
|
|
147696
147946
|
errorCodes: errorCodes,
|
|
147697
147947
|
getCodeActions: function (context) {
|
|
147698
|
-
var errorCode = context.errorCode, preferences = context.preferences, sourceFile = context.sourceFile, span = context.span;
|
|
147948
|
+
var errorCode = context.errorCode, preferences = context.preferences, sourceFile = context.sourceFile, span = context.span, program = context.program;
|
|
147699
147949
|
var info = getFixesInfo(context, errorCode, span.start, /*useAutoImportProvider*/ true);
|
|
147700
147950
|
if (!info)
|
|
147701
147951
|
return undefined;
|
|
147702
147952
|
var fixes = info.fixes, symbolName = info.symbolName;
|
|
147703
147953
|
var quotePreference = ts.getQuotePreference(sourceFile, preferences);
|
|
147704
|
-
return fixes.map(function (fix) { return codeActionForFix(context, sourceFile, symbolName, fix, quotePreference); });
|
|
147954
|
+
return fixes.map(function (fix) { return codeActionForFix(context, sourceFile, symbolName, fix, quotePreference, program.getCompilerOptions()); });
|
|
147705
147955
|
},
|
|
147706
147956
|
fixIds: [importFixId],
|
|
147707
147957
|
getAllCodeActions: function (context) {
|
|
@@ -147720,8 +147970,9 @@ var ts;
|
|
|
147720
147970
|
// Namespace fixes don't conflict, so just build a list.
|
|
147721
147971
|
var addToNamespace = [];
|
|
147722
147972
|
var importType = [];
|
|
147723
|
-
|
|
147973
|
+
/** Keys are import clause node IDs. */
|
|
147724
147974
|
var addToExisting = new ts.Map();
|
|
147975
|
+
/** Use `getNewImportEntry` for access */
|
|
147725
147976
|
var newImports = new ts.Map();
|
|
147726
147977
|
return { addImportFromDiagnostic: addImportFromDiagnostic, addImportFromExportedSymbol: addImportFromExportedSymbol, writeFixes: writeFixes };
|
|
147727
147978
|
function addImportFromDiagnostic(diagnostic, context) {
|
|
@@ -147730,67 +147981,66 @@ var ts;
|
|
|
147730
147981
|
return;
|
|
147731
147982
|
addImport(info);
|
|
147732
147983
|
}
|
|
147733
|
-
function addImportFromExportedSymbol(exportedSymbol,
|
|
147984
|
+
function addImportFromExportedSymbol(exportedSymbol, isValidTypeOnlyUseSite) {
|
|
147734
147985
|
var moduleSymbol = ts.Debug.checkDefined(exportedSymbol.parent);
|
|
147735
147986
|
var symbolName = ts.getNameForExportedSymbol(exportedSymbol, ts.getEmitScriptTarget(compilerOptions));
|
|
147736
147987
|
var checker = program.getTypeChecker();
|
|
147737
147988
|
var symbol = checker.getMergedSymbol(ts.skipAlias(exportedSymbol, checker));
|
|
147738
147989
|
var exportInfos = getAllReExportingModules(sourceFile, symbol, moduleSymbol, symbolName, host, program, preferences, useAutoImportProvider);
|
|
147739
|
-
var preferTypeOnlyImport = !!usageIsTypeOnly && compilerOptions.importsNotUsedAsValues === 2 /* Error */;
|
|
147740
147990
|
var useRequire = shouldUseRequire(sourceFile, program);
|
|
147741
|
-
var fix = getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, /*position*/ undefined,
|
|
147991
|
+
var fix = getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, /*position*/ undefined, !!isValidTypeOnlyUseSite, useRequire, host, preferences);
|
|
147742
147992
|
if (fix) {
|
|
147743
147993
|
addImport({ fixes: [fix], symbolName: symbolName });
|
|
147744
147994
|
}
|
|
147745
147995
|
}
|
|
147746
147996
|
function addImport(info) {
|
|
147997
|
+
var _a, _b;
|
|
147747
147998
|
var fixes = info.fixes, symbolName = info.symbolName;
|
|
147748
147999
|
var fix = ts.first(fixes);
|
|
147749
148000
|
switch (fix.kind) {
|
|
147750
148001
|
case 0 /* UseNamespace */:
|
|
147751
148002
|
addToNamespace.push(fix);
|
|
147752
148003
|
break;
|
|
147753
|
-
case 1 /*
|
|
148004
|
+
case 1 /* JsdocTypeImport */:
|
|
147754
148005
|
importType.push(fix);
|
|
147755
148006
|
break;
|
|
147756
148007
|
case 2 /* AddToExisting */: {
|
|
147757
|
-
var importClauseOrBindingPattern = fix.importClauseOrBindingPattern, importKind = fix.importKind,
|
|
148008
|
+
var importClauseOrBindingPattern = fix.importClauseOrBindingPattern, importKind = fix.importKind, addAsTypeOnly = fix.addAsTypeOnly;
|
|
147758
148009
|
var key = String(ts.getNodeId(importClauseOrBindingPattern));
|
|
147759
148010
|
var entry = addToExisting.get(key);
|
|
147760
148011
|
if (!entry) {
|
|
147761
|
-
addToExisting.set(key, entry = { importClauseOrBindingPattern: importClauseOrBindingPattern, defaultImport: undefined, namedImports:
|
|
148012
|
+
addToExisting.set(key, entry = { importClauseOrBindingPattern: importClauseOrBindingPattern, defaultImport: undefined, namedImports: new ts.Map() });
|
|
147762
148013
|
}
|
|
147763
148014
|
if (importKind === 0 /* Named */) {
|
|
147764
|
-
|
|
148015
|
+
var prevValue = entry === null || entry === void 0 ? void 0 : entry.namedImports.get(symbolName);
|
|
148016
|
+
entry.namedImports.set(symbolName, reduceAddAsTypeOnlyValues(prevValue, addAsTypeOnly));
|
|
147765
148017
|
}
|
|
147766
148018
|
else {
|
|
147767
|
-
ts.Debug.assert(entry.defaultImport === undefined || entry.defaultImport === symbolName, "(Add to Existing) Default import should be missing or match symbolName");
|
|
147768
|
-
entry.defaultImport =
|
|
148019
|
+
ts.Debug.assert(entry.defaultImport === undefined || entry.defaultImport.name === symbolName, "(Add to Existing) Default import should be missing or match symbolName");
|
|
148020
|
+
entry.defaultImport = {
|
|
148021
|
+
name: symbolName,
|
|
148022
|
+
addAsTypeOnly: reduceAddAsTypeOnlyValues((_a = entry.defaultImport) === null || _a === void 0 ? void 0 : _a.addAsTypeOnly, addAsTypeOnly),
|
|
148023
|
+
};
|
|
147769
148024
|
}
|
|
147770
148025
|
break;
|
|
147771
148026
|
}
|
|
147772
148027
|
case 3 /* AddNew */: {
|
|
147773
|
-
var moduleSpecifier = fix.moduleSpecifier, importKind = fix.importKind, useRequire = fix.useRequire,
|
|
147774
|
-
var entry =
|
|
147775
|
-
|
|
147776
|
-
newImports.set(moduleSpecifier, entry = { namedImports: [], namespaceLikeImport: undefined, typeOnly: typeOnly, useRequire: useRequire });
|
|
147777
|
-
}
|
|
147778
|
-
else {
|
|
147779
|
-
// An import clause can only be type-only if every import fix contributing to it can be type-only.
|
|
147780
|
-
entry.typeOnly = entry.typeOnly && typeOnly;
|
|
147781
|
-
}
|
|
148028
|
+
var moduleSpecifier = fix.moduleSpecifier, importKind = fix.importKind, useRequire = fix.useRequire, addAsTypeOnly = fix.addAsTypeOnly;
|
|
148029
|
+
var entry = getNewImportEntry(moduleSpecifier, importKind, useRequire, addAsTypeOnly);
|
|
148030
|
+
ts.Debug.assert(entry.useRequire === useRequire, "(Add new) Tried to add an `import` and a `require` for the same module");
|
|
147782
148031
|
switch (importKind) {
|
|
147783
148032
|
case 1 /* Default */:
|
|
147784
|
-
ts.Debug.assert(entry.defaultImport === undefined || entry.defaultImport === symbolName, "(Add new) Default import should be missing or match symbolName");
|
|
147785
|
-
entry.defaultImport = symbolName;
|
|
148033
|
+
ts.Debug.assert(entry.defaultImport === undefined || entry.defaultImport.name === symbolName, "(Add new) Default import should be missing or match symbolName");
|
|
148034
|
+
entry.defaultImport = { name: symbolName, addAsTypeOnly: reduceAddAsTypeOnlyValues((_b = entry.defaultImport) === null || _b === void 0 ? void 0 : _b.addAsTypeOnly, addAsTypeOnly) };
|
|
147786
148035
|
break;
|
|
147787
148036
|
case 0 /* Named */:
|
|
147788
|
-
|
|
148037
|
+
var prevValue = (entry.namedImports || (entry.namedImports = new ts.Map())).get(symbolName);
|
|
148038
|
+
entry.namedImports.set(symbolName, reduceAddAsTypeOnlyValues(prevValue, addAsTypeOnly));
|
|
147789
148039
|
break;
|
|
147790
148040
|
case 3 /* CommonJS */:
|
|
147791
148041
|
case 2 /* Namespace */:
|
|
147792
148042
|
ts.Debug.assert(entry.namespaceLikeImport === undefined || entry.namespaceLikeImport.name === symbolName, "Namespacelike import shoudl be missing or match symbolName");
|
|
147793
|
-
entry.namespaceLikeImport = { importKind: importKind, name: symbolName };
|
|
148043
|
+
entry.namespaceLikeImport = { importKind: importKind, name: symbolName, addAsTypeOnly: addAsTypeOnly };
|
|
147794
148044
|
break;
|
|
147795
148045
|
}
|
|
147796
148046
|
break;
|
|
@@ -147798,6 +148048,50 @@ var ts;
|
|
|
147798
148048
|
default:
|
|
147799
148049
|
ts.Debug.assertNever(fix, "fix wasn't never - got kind " + fix.kind);
|
|
147800
148050
|
}
|
|
148051
|
+
function reduceAddAsTypeOnlyValues(prevValue, newValue) {
|
|
148052
|
+
// `NotAllowed` overrides `Required` because one addition of a new import might be required to be type-only
|
|
148053
|
+
// because of `--importsNotUsedAsValues=error`, but if a second addition of the same import is `NotAllowed`
|
|
148054
|
+
// to be type-only, the reason the first one was `Required` - the unused runtime dependency - is now moot.
|
|
148055
|
+
// Alternatively, if one addition is `Required` because it has no value meaning under `--preserveValueImports`
|
|
148056
|
+
// and `--isolatedModules`, it should be impossible for another addition to be `NotAllowed` since that would
|
|
148057
|
+
// mean a type is being referenced in a value location.
|
|
148058
|
+
return Math.max(prevValue !== null && prevValue !== void 0 ? prevValue : 0, newValue);
|
|
148059
|
+
}
|
|
148060
|
+
function getNewImportEntry(moduleSpecifier, importKind, useRequire, addAsTypeOnly) {
|
|
148061
|
+
// A default import that requires type-only makes the whole import type-only.
|
|
148062
|
+
// (We could add `default` as a named import, but that style seems undesirable.)
|
|
148063
|
+
// Under `--preserveValueImports` and `--importsNotUsedAsValues=error`, if a
|
|
148064
|
+
// module default-exports a type but named-exports some values (weird), you would
|
|
148065
|
+
// have to use a type-only default import and non-type-only named imports. These
|
|
148066
|
+
// require two separate import declarations, so we build this into the map key.
|
|
148067
|
+
var typeOnlyKey = newImportsKey(moduleSpecifier, /*topLevelTypeOnly*/ true);
|
|
148068
|
+
var nonTypeOnlyKey = newImportsKey(moduleSpecifier, /*topLevelTypeOnly*/ false);
|
|
148069
|
+
var typeOnlyEntry = newImports.get(typeOnlyKey);
|
|
148070
|
+
var nonTypeOnlyEntry = newImports.get(nonTypeOnlyKey);
|
|
148071
|
+
var newEntry = {
|
|
148072
|
+
defaultImport: undefined,
|
|
148073
|
+
namedImports: undefined,
|
|
148074
|
+
namespaceLikeImport: undefined,
|
|
148075
|
+
useRequire: useRequire
|
|
148076
|
+
};
|
|
148077
|
+
if (importKind === 1 /* Default */ && addAsTypeOnly === 2 /* Required */) {
|
|
148078
|
+
if (typeOnlyEntry)
|
|
148079
|
+
return typeOnlyEntry;
|
|
148080
|
+
newImports.set(typeOnlyKey, newEntry);
|
|
148081
|
+
return newEntry;
|
|
148082
|
+
}
|
|
148083
|
+
if (addAsTypeOnly === 1 /* Allowed */ && (typeOnlyEntry || nonTypeOnlyEntry)) {
|
|
148084
|
+
return (typeOnlyEntry || nonTypeOnlyEntry);
|
|
148085
|
+
}
|
|
148086
|
+
if (nonTypeOnlyEntry) {
|
|
148087
|
+
return nonTypeOnlyEntry;
|
|
148088
|
+
}
|
|
148089
|
+
newImports.set(nonTypeOnlyKey, newEntry);
|
|
148090
|
+
return newEntry;
|
|
148091
|
+
}
|
|
148092
|
+
function newImportsKey(moduleSpecifier, topLevelTypeOnly) {
|
|
148093
|
+
return (topLevelTypeOnly ? 1 : 0) + "|" + moduleSpecifier;
|
|
148094
|
+
}
|
|
147801
148095
|
}
|
|
147802
148096
|
function writeFixes(changeTracker) {
|
|
147803
148097
|
var quotePreference = ts.getQuotePreference(sourceFile, preferences);
|
|
@@ -147810,14 +148104,22 @@ var ts;
|
|
|
147810
148104
|
addImportType(changeTracker, sourceFile, fix, quotePreference);
|
|
147811
148105
|
}
|
|
147812
148106
|
addToExisting.forEach(function (_a) {
|
|
147813
|
-
var importClauseOrBindingPattern = _a.importClauseOrBindingPattern, defaultImport = _a.defaultImport, namedImports = _a.namedImports
|
|
147814
|
-
doAddExistingFix(changeTracker, sourceFile, importClauseOrBindingPattern, defaultImport, namedImports,
|
|
148107
|
+
var importClauseOrBindingPattern = _a.importClauseOrBindingPattern, defaultImport = _a.defaultImport, namedImports = _a.namedImports;
|
|
148108
|
+
doAddExistingFix(changeTracker, sourceFile, importClauseOrBindingPattern, defaultImport, ts.arrayFrom(namedImports.entries(), function (_a) {
|
|
148109
|
+
var name = _a[0], addAsTypeOnly = _a[1];
|
|
148110
|
+
return ({ addAsTypeOnly: addAsTypeOnly, name: name });
|
|
148111
|
+
}), compilerOptions);
|
|
147815
148112
|
});
|
|
147816
148113
|
var newDeclarations;
|
|
147817
|
-
newImports.forEach(function (_a,
|
|
147818
|
-
var useRequire = _a.useRequire,
|
|
148114
|
+
newImports.forEach(function (_a, key) {
|
|
148115
|
+
var useRequire = _a.useRequire, defaultImport = _a.defaultImport, namedImports = _a.namedImports, namespaceLikeImport = _a.namespaceLikeImport;
|
|
148116
|
+
var moduleSpecifier = key.slice(2); // From `${0 | 1}|${moduleSpecifier}` format
|
|
147819
148117
|
var getDeclarations = useRequire ? getNewRequires : getNewImports;
|
|
147820
|
-
|
|
148118
|
+
var declarations = getDeclarations(moduleSpecifier, quotePreference, defaultImport, namedImports && ts.arrayFrom(namedImports.entries(), function (_a) {
|
|
148119
|
+
var name = _a[0], addAsTypeOnly = _a[1];
|
|
148120
|
+
return ({ addAsTypeOnly: addAsTypeOnly, name: name });
|
|
148121
|
+
}), namespaceLikeImport);
|
|
148122
|
+
newDeclarations = ts.combine(newDeclarations, declarations);
|
|
147821
148123
|
});
|
|
147822
148124
|
if (newDeclarations) {
|
|
147823
148125
|
ts.insertImports(changeTracker, sourceFile, newDeclarations, /*blankLineBetween*/ true);
|
|
@@ -147828,24 +148130,37 @@ var ts;
|
|
|
147828
148130
|
var ImportFixKind;
|
|
147829
148131
|
(function (ImportFixKind) {
|
|
147830
148132
|
ImportFixKind[ImportFixKind["UseNamespace"] = 0] = "UseNamespace";
|
|
147831
|
-
ImportFixKind[ImportFixKind["
|
|
148133
|
+
ImportFixKind[ImportFixKind["JsdocTypeImport"] = 1] = "JsdocTypeImport";
|
|
147832
148134
|
ImportFixKind[ImportFixKind["AddToExisting"] = 2] = "AddToExisting";
|
|
147833
148135
|
ImportFixKind[ImportFixKind["AddNew"] = 3] = "AddNew";
|
|
147834
148136
|
})(ImportFixKind || (ImportFixKind = {}));
|
|
148137
|
+
// These should not be combined as bitflags, but are given powers of 2 values to
|
|
148138
|
+
// easily detect conflicts between `NotAllowed` and `Required` by giving them a unique sum.
|
|
148139
|
+
// They're also ordered in terms of increasing priority for a fix-all scenario (see
|
|
148140
|
+
// `reduceAddAsTypeOnlyValues`).
|
|
148141
|
+
var AddAsTypeOnly;
|
|
148142
|
+
(function (AddAsTypeOnly) {
|
|
148143
|
+
AddAsTypeOnly[AddAsTypeOnly["Allowed"] = 1] = "Allowed";
|
|
148144
|
+
AddAsTypeOnly[AddAsTypeOnly["Required"] = 2] = "Required";
|
|
148145
|
+
AddAsTypeOnly[AddAsTypeOnly["NotAllowed"] = 4] = "NotAllowed";
|
|
148146
|
+
})(AddAsTypeOnly || (AddAsTypeOnly = {}));
|
|
147835
148147
|
function getImportCompletionAction(exportedSymbol, moduleSymbol, sourceFile, symbolName, host, program, formatContext, position, preferences) {
|
|
147836
148148
|
var compilerOptions = program.getCompilerOptions();
|
|
147837
148149
|
var exportInfos = ts.pathIsBareSpecifier(ts.stripQuotes(moduleSymbol.name))
|
|
147838
148150
|
? [getSymbolExportInfoForSymbol(exportedSymbol, moduleSymbol, program, host)]
|
|
147839
148151
|
: getAllReExportingModules(sourceFile, exportedSymbol, moduleSymbol, symbolName, host, program, preferences, /*useAutoImportProvider*/ true);
|
|
147840
148152
|
var useRequire = shouldUseRequire(sourceFile, program);
|
|
147841
|
-
var
|
|
147842
|
-
var fix = ts.Debug.checkDefined(getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position,
|
|
147843
|
-
return {
|
|
148153
|
+
var isValidTypeOnlyUseSite = ts.isValidTypeOnlyAliasUseSite(ts.getTokenAtPosition(sourceFile, position));
|
|
148154
|
+
var fix = ts.Debug.checkDefined(getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences));
|
|
148155
|
+
return {
|
|
148156
|
+
moduleSpecifier: fix.moduleSpecifier,
|
|
148157
|
+
codeAction: codeFixActionToCodeAction(codeActionForFix({ host: host, formatContext: formatContext, preferences: preferences }, sourceFile, symbolName, fix, ts.getQuotePreference(sourceFile, preferences), compilerOptions))
|
|
148158
|
+
};
|
|
147844
148159
|
}
|
|
147845
148160
|
codefix.getImportCompletionAction = getImportCompletionAction;
|
|
147846
|
-
function getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position,
|
|
148161
|
+
function getImportFixForSymbol(sourceFile, exportInfos, moduleSymbol, symbolName, program, position, isValidTypeOnlyUseSite, useRequire, host, preferences) {
|
|
147847
148162
|
ts.Debug.assert(exportInfos.some(function (info) { return info.moduleSymbol === moduleSymbol || info.symbol.parent === moduleSymbol; }), "Some exportInfo should match the specified moduleSymbol");
|
|
147848
|
-
return getBestFix(getImportFixes(exportInfos, symbolName, position,
|
|
148163
|
+
return getBestFix(getImportFixes(exportInfos, symbolName, position, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences), sourceFile, program, host, preferences);
|
|
147849
148164
|
}
|
|
147850
148165
|
function codeFixActionToCodeAction(_a) {
|
|
147851
148166
|
var description = _a.description, changes = _a.changes, commands = _a.commands;
|
|
@@ -147903,24 +148218,21 @@ var ts;
|
|
|
147903
148218
|
function getModuleSpecifierForBestExportInfo(exportInfo, importingFile, program, host, preferences, fromCacheOnly) {
|
|
147904
148219
|
var _a = getNewImportFixes(program, importingFile,
|
|
147905
148220
|
/*position*/ undefined,
|
|
147906
|
-
/*
|
|
148221
|
+
/*isValidTypeOnlyUseSite*/ false,
|
|
147907
148222
|
/*useRequire*/ false, exportInfo, host, preferences, fromCacheOnly), fixes = _a.fixes, computedWithoutCacheCount = _a.computedWithoutCacheCount;
|
|
147908
148223
|
var result = getBestFix(fixes, importingFile, program, host, preferences);
|
|
147909
148224
|
return result && __assign(__assign({}, result), { computedWithoutCacheCount: computedWithoutCacheCount });
|
|
147910
148225
|
}
|
|
147911
148226
|
codefix.getModuleSpecifierForBestExportInfo = getModuleSpecifierForBestExportInfo;
|
|
147912
|
-
function isTypeOnlyPosition(sourceFile, position) {
|
|
147913
|
-
return ts.isValidTypeOnlyAliasUseSite(ts.getTokenAtPosition(sourceFile, position));
|
|
147914
|
-
}
|
|
147915
148227
|
function getImportFixes(exportInfos, symbolName,
|
|
147916
148228
|
/** undefined only for missing JSX namespace */
|
|
147917
|
-
position,
|
|
148229
|
+
position, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences) {
|
|
147918
148230
|
var checker = program.getTypeChecker();
|
|
147919
148231
|
var existingImports = ts.flatMap(exportInfos, function (info) { return getExistingImportDeclarations(info, checker, sourceFile, program.getCompilerOptions()); });
|
|
147920
148232
|
var useNamespace = position === undefined ? undefined : tryUseExistingNamespaceImport(existingImports, symbolName, position, checker);
|
|
147921
|
-
var addToExisting = tryAddToExistingImport(existingImports,
|
|
148233
|
+
var addToExisting = tryAddToExistingImport(existingImports, isValidTypeOnlyUseSite, checker, program.getCompilerOptions());
|
|
147922
148234
|
// Don't bother providing an action to add a new import if we can add to an existing one.
|
|
147923
|
-
var addImport = addToExisting ? [addToExisting] : getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position,
|
|
148235
|
+
var addImport = addToExisting ? [addToExisting] : getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, host, preferences);
|
|
147924
148236
|
return __spreadArray(__spreadArray([], (useNamespace ? [useNamespace] : ts.emptyArray), true), addImport, true);
|
|
147925
148237
|
}
|
|
147926
148238
|
function tryUseExistingNamespaceImport(existingImports, symbolName, position, checker) {
|
|
@@ -147975,14 +148287,34 @@ var ts;
|
|
|
147975
148287
|
return ts.Debug.assertNever(declaration);
|
|
147976
148288
|
}
|
|
147977
148289
|
}
|
|
147978
|
-
function
|
|
148290
|
+
function getAddAsTypeOnly(isValidTypeOnlyUseSite, isForNewImportDeclaration, symbol, targetFlags, checker, compilerOptions) {
|
|
148291
|
+
if (!isValidTypeOnlyUseSite) {
|
|
148292
|
+
// Can't use a type-only import if the usage is an emitting position
|
|
148293
|
+
return 4 /* NotAllowed */;
|
|
148294
|
+
}
|
|
148295
|
+
if (isForNewImportDeclaration && compilerOptions.importsNotUsedAsValues === 2 /* Error */) {
|
|
148296
|
+
// Not writing a (top-level) type-only import here would create an error because the runtime dependency is unnecessary
|
|
148297
|
+
return 2 /* Required */;
|
|
148298
|
+
}
|
|
148299
|
+
if (compilerOptions.isolatedModules && compilerOptions.preserveValueImports &&
|
|
148300
|
+
(!(targetFlags & 111551 /* Value */) || !!checker.getTypeOnlyAliasDeclaration(symbol))) {
|
|
148301
|
+
// A type-only import is required for this symbol if under these settings if the symbol will
|
|
148302
|
+
// be erased, which will happen if the target symbol is purely a type or if it was exported/imported
|
|
148303
|
+
// as type-only already somewhere between this import and the target.
|
|
148304
|
+
return 2 /* Required */;
|
|
148305
|
+
}
|
|
148306
|
+
return 1 /* Allowed */;
|
|
148307
|
+
}
|
|
148308
|
+
function tryAddToExistingImport(existingImports, isValidTypeOnlyUseSite, checker, compilerOptions) {
|
|
147979
148309
|
return ts.firstDefined(existingImports, function (_a) {
|
|
147980
|
-
var declaration = _a.declaration, importKind = _a.importKind;
|
|
147981
|
-
if (declaration.kind === 264 /* ImportEqualsDeclaration */)
|
|
148310
|
+
var declaration = _a.declaration, importKind = _a.importKind, symbol = _a.symbol, targetFlags = _a.targetFlags;
|
|
148311
|
+
if (importKind === 3 /* CommonJS */ || importKind === 2 /* Namespace */ || declaration.kind === 264 /* ImportEqualsDeclaration */) {
|
|
148312
|
+
// These kinds of imports are not combinable with anything
|
|
147982
148313
|
return undefined;
|
|
148314
|
+
}
|
|
147983
148315
|
if (declaration.kind === 253 /* VariableDeclaration */) {
|
|
147984
148316
|
return (importKind === 0 /* Named */ || importKind === 1 /* Default */) && declaration.name.kind === 200 /* ObjectBindingPattern */
|
|
147985
|
-
? { kind: 2 /* AddToExisting */, importClauseOrBindingPattern: declaration.name, importKind: importKind, moduleSpecifier: declaration.initializer.arguments[0].text,
|
|
148317
|
+
? { kind: 2 /* AddToExisting */, importClauseOrBindingPattern: declaration.name, importKind: importKind, moduleSpecifier: declaration.initializer.arguments[0].text, addAsTypeOnly: 4 /* NotAllowed */ }
|
|
147986
148318
|
: undefined;
|
|
147987
148319
|
}
|
|
147988
148320
|
var importClause = declaration.importClause;
|
|
@@ -147993,13 +148325,29 @@ var ts;
|
|
|
147993
148325
|
// be added to an existing type-only import is adding a named import to existing named bindings.
|
|
147994
148326
|
if (importClause.isTypeOnly && !(importKind === 0 /* Named */ && namedBindings))
|
|
147995
148327
|
return undefined;
|
|
147996
|
-
|
|
147997
|
-
|
|
147998
|
-
|
|
148328
|
+
// N.B. we don't have to figure out whether to use the main program checker
|
|
148329
|
+
// or the AutoImportProvider checker because we're adding to an existing import; the existence of
|
|
148330
|
+
// the import guarantees the symbol came from the main program.
|
|
148331
|
+
var addAsTypeOnly = getAddAsTypeOnly(isValidTypeOnlyUseSite, /*isForNewImportDeclaration*/ false, symbol, targetFlags, checker, compilerOptions);
|
|
148332
|
+
if (importKind === 1 /* Default */ && (name || // Cannot add a default import to a declaration that already has one
|
|
148333
|
+
addAsTypeOnly === 2 /* Required */ && namedBindings // Cannot add a default import as type-only if the import already has named bindings
|
|
148334
|
+
))
|
|
148335
|
+
return undefined;
|
|
148336
|
+
if (importKind === 0 /* Named */ &&
|
|
148337
|
+
(namedBindings === null || namedBindings === void 0 ? void 0 : namedBindings.kind) === 267 /* NamespaceImport */ // Cannot add a named import to a declaration that has a namespace import
|
|
148338
|
+
)
|
|
148339
|
+
return undefined;
|
|
148340
|
+
return {
|
|
148341
|
+
kind: 2 /* AddToExisting */,
|
|
148342
|
+
importClauseOrBindingPattern: importClause,
|
|
148343
|
+
importKind: importKind,
|
|
148344
|
+
moduleSpecifier: declaration.moduleSpecifier.text,
|
|
148345
|
+
addAsTypeOnly: addAsTypeOnly,
|
|
148346
|
+
};
|
|
147999
148347
|
});
|
|
148000
148348
|
}
|
|
148001
148349
|
function getExistingImportDeclarations(_a, checker, importingFile, compilerOptions) {
|
|
148002
|
-
var moduleSymbol = _a.moduleSymbol, exportKind = _a.exportKind, targetFlags = _a.targetFlags;
|
|
148350
|
+
var moduleSymbol = _a.moduleSymbol, exportKind = _a.exportKind, targetFlags = _a.targetFlags, symbol = _a.symbol;
|
|
148003
148351
|
// Can't use an es6 import for a type in JS.
|
|
148004
148352
|
if (!(targetFlags & 111551 /* Value */) && ts.isSourceFileJS(importingFile))
|
|
148005
148353
|
return ts.emptyArray;
|
|
@@ -148007,10 +148355,10 @@ var ts;
|
|
|
148007
148355
|
return ts.mapDefined(importingFile.imports, function (moduleSpecifier) {
|
|
148008
148356
|
var i = ts.importFromModuleSpecifier(moduleSpecifier);
|
|
148009
148357
|
if (ts.isRequireVariableDeclaration(i.parent)) {
|
|
148010
|
-
return checker.resolveExternalModuleName(moduleSpecifier) === moduleSymbol ? { declaration: i.parent, importKind: importKind } : undefined;
|
|
148358
|
+
return checker.resolveExternalModuleName(moduleSpecifier) === moduleSymbol ? { declaration: i.parent, importKind: importKind, symbol: symbol, targetFlags: targetFlags } : undefined;
|
|
148011
148359
|
}
|
|
148012
148360
|
if (i.kind === 265 /* ImportDeclaration */ || i.kind === 264 /* ImportEqualsDeclaration */) {
|
|
148013
|
-
return checker.getSymbolAtLocation(moduleSpecifier) === moduleSymbol ? { declaration: i, importKind: importKind } : undefined;
|
|
148361
|
+
return checker.getSymbolAtLocation(moduleSpecifier) === moduleSymbol ? { declaration: i, importKind: importKind, symbol: symbol, targetFlags: targetFlags } : undefined;
|
|
148014
148362
|
}
|
|
148015
148363
|
});
|
|
148016
148364
|
}
|
|
@@ -148042,44 +148390,50 @@ var ts;
|
|
|
148042
148390
|
// 5. Literally nothing to go on
|
|
148043
148391
|
return true;
|
|
148044
148392
|
}
|
|
148045
|
-
function getNewImportFixes(program, sourceFile, position,
|
|
148393
|
+
function getNewImportFixes(program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, moduleSymbols, host, preferences, fromCacheOnly) {
|
|
148046
148394
|
var isJs = ts.isSourceFileJS(sourceFile);
|
|
148047
148395
|
var compilerOptions = program.getCompilerOptions();
|
|
148048
148396
|
var moduleSpecifierResolutionHost = ts.createModuleSpecifierResolutionHost(program, host);
|
|
148049
|
-
var
|
|
148397
|
+
var getChecker = ts.memoizeOne(function (isFromPackageJson) { return isFromPackageJson ? host.getPackageJsonAutoImportProvider().getTypeChecker() : program.getTypeChecker(); });
|
|
148050
148398
|
var getModuleSpecifiers = fromCacheOnly
|
|
148051
148399
|
? function (moduleSymbol) { return ({ moduleSpecifiers: ts.moduleSpecifiers.tryGetModuleSpecifiersFromCache(moduleSymbol, sourceFile, moduleSpecifierResolutionHost, preferences), computedWithoutCache: false }); }
|
|
148052
|
-
: function (moduleSymbol) { return ts.moduleSpecifiers.getModuleSpecifiersWithCacheInfo(moduleSymbol, checker, compilerOptions, sourceFile, moduleSpecifierResolutionHost, preferences); };
|
|
148400
|
+
: function (moduleSymbol, checker) { return ts.moduleSpecifiers.getModuleSpecifiersWithCacheInfo(moduleSymbol, checker, compilerOptions, sourceFile, moduleSpecifierResolutionHost, preferences); };
|
|
148053
148401
|
var computedWithoutCacheCount = 0;
|
|
148054
148402
|
var fixes = ts.flatMap(moduleSymbols, function (exportInfo) {
|
|
148055
|
-
var
|
|
148403
|
+
var checker = getChecker(exportInfo.isFromPackageJson);
|
|
148404
|
+
var _a = getModuleSpecifiers(exportInfo.moduleSymbol, checker), computedWithoutCache = _a.computedWithoutCache, moduleSpecifiers = _a.moduleSpecifiers;
|
|
148405
|
+
var importedSymbolHasValueMeaning = !!(exportInfo.targetFlags & 111551 /* Value */);
|
|
148406
|
+
var addAsTypeOnly = getAddAsTypeOnly(isValidTypeOnlyUseSite, /*isForNewImportDeclaration*/ true, exportInfo.symbol, exportInfo.targetFlags, checker, compilerOptions);
|
|
148056
148407
|
computedWithoutCacheCount += computedWithoutCache ? 1 : 0;
|
|
148057
148408
|
return moduleSpecifiers === null || moduleSpecifiers === void 0 ? void 0 : moduleSpecifiers.map(function (moduleSpecifier) {
|
|
148058
148409
|
// `position` should only be undefined at a missing jsx namespace, in which case we shouldn't be looking for pure types.
|
|
148059
|
-
return !
|
|
148060
|
-
? { kind: 1 /*
|
|
148410
|
+
return !importedSymbolHasValueMeaning && isJs && position !== undefined
|
|
148411
|
+
? { kind: 1 /* JsdocTypeImport */, moduleSpecifier: moduleSpecifier, position: position, exportInfo: exportInfo }
|
|
148061
148412
|
: {
|
|
148062
148413
|
kind: 3 /* AddNew */,
|
|
148063
148414
|
moduleSpecifier: moduleSpecifier,
|
|
148064
148415
|
importKind: getImportKind(sourceFile, exportInfo.exportKind, compilerOptions),
|
|
148065
148416
|
useRequire: useRequire,
|
|
148066
|
-
|
|
148417
|
+
addAsTypeOnly: addAsTypeOnly,
|
|
148067
148418
|
exportInfo: exportInfo,
|
|
148068
148419
|
};
|
|
148069
148420
|
});
|
|
148070
148421
|
});
|
|
148071
148422
|
return { computedWithoutCacheCount: computedWithoutCacheCount, fixes: fixes };
|
|
148072
148423
|
}
|
|
148073
|
-
function getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position,
|
|
148074
|
-
var existingDeclaration = ts.firstDefined(existingImports, function (info) { return newImportInfoFromExistingSpecifier(info,
|
|
148075
|
-
return existingDeclaration ? [existingDeclaration] : getNewImportFixes(program, sourceFile, position,
|
|
148424
|
+
function getFixesForAddImport(exportInfos, existingImports, program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, host, preferences) {
|
|
148425
|
+
var existingDeclaration = ts.firstDefined(existingImports, function (info) { return newImportInfoFromExistingSpecifier(info, isValidTypeOnlyUseSite, useRequire, program.getTypeChecker(), program.getCompilerOptions()); });
|
|
148426
|
+
return existingDeclaration ? [existingDeclaration] : getNewImportFixes(program, sourceFile, position, isValidTypeOnlyUseSite, useRequire, exportInfos, host, preferences).fixes;
|
|
148076
148427
|
}
|
|
148077
|
-
function newImportInfoFromExistingSpecifier(_a,
|
|
148078
|
-
var declaration = _a.declaration, importKind = _a.importKind;
|
|
148428
|
+
function newImportInfoFromExistingSpecifier(_a, isValidTypeOnlyUseSite, useRequire, checker, compilerOptions) {
|
|
148429
|
+
var declaration = _a.declaration, importKind = _a.importKind, symbol = _a.symbol, targetFlags = _a.targetFlags;
|
|
148079
148430
|
var moduleSpecifier = ts.tryGetModuleSpecifierFromDeclaration(declaration);
|
|
148080
|
-
|
|
148081
|
-
|
|
148082
|
-
|
|
148431
|
+
if (moduleSpecifier) {
|
|
148432
|
+
var addAsTypeOnly = useRequire
|
|
148433
|
+
? 4 /* NotAllowed */
|
|
148434
|
+
: getAddAsTypeOnly(isValidTypeOnlyUseSite, /*isForNewImportDeclaration*/ true, symbol, targetFlags, checker, compilerOptions);
|
|
148435
|
+
return { kind: 3 /* AddNew */, moduleSpecifier: moduleSpecifier, importKind: importKind, addAsTypeOnly: addAsTypeOnly, useRequire: useRequire };
|
|
148436
|
+
}
|
|
148083
148437
|
}
|
|
148084
148438
|
function getFixesInfo(context, errorCode, pos, useAutoImportProvider) {
|
|
148085
148439
|
var symbolToken = ts.getTokenAtPosition(context.sourceFile, pos);
|
|
@@ -148129,7 +148483,7 @@ var ts;
|
|
|
148129
148483
|
var symbolName = umdSymbol.name;
|
|
148130
148484
|
var exportInfos = [{ symbol: umdSymbol, moduleSymbol: symbol, moduleFileName: undefined, exportKind: 3 /* UMD */, targetFlags: symbol.flags, isFromPackageJson: false }];
|
|
148131
148485
|
var useRequire = shouldUseRequire(sourceFile, program);
|
|
148132
|
-
var fixes = getImportFixes(exportInfos, symbolName, ts.isIdentifier(token) ? token.getStart(sourceFile) : undefined, /*
|
|
148486
|
+
var fixes = getImportFixes(exportInfos, symbolName, ts.isIdentifier(token) ? token.getStart(sourceFile) : undefined, /*isValidTypeOnlyUseSite*/ false, useRequire, program, sourceFile, host, preferences);
|
|
148133
148487
|
return { fixes: fixes, symbolName: symbolName };
|
|
148134
148488
|
}
|
|
148135
148489
|
function getUmdSymbol(token, checker) {
|
|
@@ -148193,12 +148547,12 @@ var ts;
|
|
|
148193
148547
|
var symbolName = getSymbolName(sourceFile, checker, symbolToken, compilerOptions);
|
|
148194
148548
|
// "default" is a keyword and not a legal identifier for the import, so we don't expect it here
|
|
148195
148549
|
ts.Debug.assert(symbolName !== "default" /* Default */, "'default' isn't a legal identifier and couldn't occur here");
|
|
148196
|
-
var
|
|
148550
|
+
var isValidTypeOnlyUseSite = ts.isValidTypeOnlyAliasUseSite(symbolToken);
|
|
148197
148551
|
var useRequire = shouldUseRequire(sourceFile, program);
|
|
148198
148552
|
var exportInfos = getExportInfos(symbolName, ts.getMeaningFromLocation(symbolToken), cancellationToken, sourceFile, program, useAutoImportProvider, host, preferences);
|
|
148199
148553
|
var fixes = ts.arrayFrom(ts.flatMapIterator(exportInfos.entries(), function (_a) {
|
|
148200
148554
|
var _ = _a[0], exportInfos = _a[1];
|
|
148201
|
-
return getImportFixes(exportInfos, symbolName, symbolToken.getStart(sourceFile),
|
|
148555
|
+
return getImportFixes(exportInfos, symbolName, symbolToken.getStart(sourceFile), isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences);
|
|
148202
148556
|
}));
|
|
148203
148557
|
return { fixes: fixes, symbolName: symbolName };
|
|
148204
148558
|
}
|
|
@@ -148276,63 +148630,81 @@ var ts;
|
|
|
148276
148630
|
// allowSyntheticDefaultImports/esModuleInterop is enabled.
|
|
148277
148631
|
return allowSyntheticDefaults ? 1 /* Default */ : 3 /* CommonJS */;
|
|
148278
148632
|
}
|
|
148279
|
-
function codeActionForFix(context, sourceFile, symbolName, fix, quotePreference) {
|
|
148633
|
+
function codeActionForFix(context, sourceFile, symbolName, fix, quotePreference, compilerOptions) {
|
|
148280
148634
|
var diag;
|
|
148281
148635
|
var changes = ts.textChanges.ChangeTracker.with(context, function (tracker) {
|
|
148282
|
-
diag = codeActionForFixWorker(tracker, sourceFile, symbolName, fix, quotePreference);
|
|
148636
|
+
diag = codeActionForFixWorker(tracker, sourceFile, symbolName, fix, quotePreference, compilerOptions);
|
|
148283
148637
|
});
|
|
148284
148638
|
return codefix.createCodeFixAction(codefix.importFixName, changes, diag, importFixId, ts.Diagnostics.Add_all_missing_imports);
|
|
148285
148639
|
}
|
|
148286
|
-
function codeActionForFixWorker(changes, sourceFile, symbolName, fix, quotePreference) {
|
|
148640
|
+
function codeActionForFixWorker(changes, sourceFile, symbolName, fix, quotePreference, compilerOptions) {
|
|
148287
148641
|
switch (fix.kind) {
|
|
148288
148642
|
case 0 /* UseNamespace */:
|
|
148289
148643
|
addNamespaceQualifier(changes, sourceFile, fix);
|
|
148290
148644
|
return [ts.Diagnostics.Change_0_to_1, symbolName, fix.namespacePrefix + "." + symbolName];
|
|
148291
|
-
case 1 /*
|
|
148645
|
+
case 1 /* JsdocTypeImport */:
|
|
148292
148646
|
addImportType(changes, sourceFile, fix, quotePreference);
|
|
148293
148647
|
return [ts.Diagnostics.Change_0_to_1, symbolName, getImportTypePrefix(fix.moduleSpecifier, quotePreference) + symbolName];
|
|
148294
148648
|
case 2 /* AddToExisting */: {
|
|
148295
|
-
var importClauseOrBindingPattern = fix.importClauseOrBindingPattern, importKind = fix.importKind,
|
|
148296
|
-
doAddExistingFix(changes, sourceFile, importClauseOrBindingPattern, importKind === 1 /* Default */ ? symbolName : undefined, importKind === 0 /* Named */ ? [symbolName] : ts.emptyArray,
|
|
148649
|
+
var importClauseOrBindingPattern = fix.importClauseOrBindingPattern, importKind = fix.importKind, addAsTypeOnly = fix.addAsTypeOnly, moduleSpecifier = fix.moduleSpecifier;
|
|
148650
|
+
doAddExistingFix(changes, sourceFile, importClauseOrBindingPattern, importKind === 1 /* Default */ ? { name: symbolName, addAsTypeOnly: addAsTypeOnly } : undefined, importKind === 0 /* Named */ ? [{ name: symbolName, addAsTypeOnly: addAsTypeOnly }] : ts.emptyArray, compilerOptions);
|
|
148297
148651
|
var moduleSpecifierWithoutQuotes = ts.stripQuotes(moduleSpecifier);
|
|
148298
|
-
return [
|
|
148652
|
+
return [
|
|
148653
|
+
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,
|
|
148654
|
+
symbolName,
|
|
148655
|
+
moduleSpecifierWithoutQuotes
|
|
148656
|
+
]; // you too!
|
|
148299
148657
|
}
|
|
148300
148658
|
case 3 /* AddNew */: {
|
|
148301
|
-
var importKind = fix.importKind, moduleSpecifier = fix.moduleSpecifier,
|
|
148659
|
+
var importKind = fix.importKind, moduleSpecifier = fix.moduleSpecifier, addAsTypeOnly = fix.addAsTypeOnly, useRequire = fix.useRequire;
|
|
148302
148660
|
var getDeclarations = useRequire ? getNewRequires : getNewImports;
|
|
148303
|
-
var
|
|
148304
|
-
|
|
148305
|
-
|
|
148306
|
-
ts.insertImports(changes, sourceFile, getDeclarations(moduleSpecifier, quotePreference,
|
|
148661
|
+
var defaultImport = importKind === 1 /* Default */ ? { name: symbolName, addAsTypeOnly: addAsTypeOnly } : undefined;
|
|
148662
|
+
var namedImports = importKind === 0 /* Named */ ? [{ name: symbolName, addAsTypeOnly: addAsTypeOnly }] : undefined;
|
|
148663
|
+
var namespaceLikeImport = importKind === 2 /* Namespace */ || importKind === 3 /* CommonJS */ ? { importKind: importKind, name: symbolName, addAsTypeOnly: addAsTypeOnly } : undefined;
|
|
148664
|
+
ts.insertImports(changes, sourceFile, getDeclarations(moduleSpecifier, quotePreference, defaultImport, namedImports, namespaceLikeImport), /*blankLineBetween*/ true);
|
|
148307
148665
|
return [importKind === 1 /* Default */ ? ts.Diagnostics.Import_default_0_from_module_1 : ts.Diagnostics.Import_0_from_module_1, symbolName, moduleSpecifier];
|
|
148308
148666
|
}
|
|
148309
148667
|
default:
|
|
148310
148668
|
return ts.Debug.assertNever(fix, "Unexpected fix kind " + fix.kind);
|
|
148311
148669
|
}
|
|
148312
148670
|
}
|
|
148313
|
-
function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImports,
|
|
148671
|
+
function doAddExistingFix(changes, sourceFile, clause, defaultImport, namedImports, compilerOptions) {
|
|
148672
|
+
var _a;
|
|
148314
148673
|
if (clause.kind === 200 /* ObjectBindingPattern */) {
|
|
148315
148674
|
if (defaultImport) {
|
|
148316
|
-
addElementToBindingPattern(clause, defaultImport, "default");
|
|
148675
|
+
addElementToBindingPattern(clause, defaultImport.name, "default");
|
|
148317
148676
|
}
|
|
148318
148677
|
for (var _i = 0, namedImports_1 = namedImports; _i < namedImports_1.length; _i++) {
|
|
148319
148678
|
var specifier = namedImports_1[_i];
|
|
148320
|
-
addElementToBindingPattern(clause, specifier, /*propertyName*/ undefined);
|
|
148679
|
+
addElementToBindingPattern(clause, specifier.name, /*propertyName*/ undefined);
|
|
148321
148680
|
}
|
|
148322
148681
|
return;
|
|
148323
148682
|
}
|
|
148324
|
-
var
|
|
148683
|
+
var promoteFromTypeOnly = clause.isTypeOnly && ts.some(__spreadArray([defaultImport], namedImports, true), function (i) { return (i === null || i === void 0 ? void 0 : i.addAsTypeOnly) === 4 /* NotAllowed */; });
|
|
148684
|
+
var existingSpecifiers = clause.namedBindings && ((_a = ts.tryCast(clause.namedBindings, ts.isNamedImports)) === null || _a === void 0 ? void 0 : _a.elements);
|
|
148685
|
+
// If we are promoting from a type-only import and `--isolatedModules` and `--preserveValueImports`
|
|
148686
|
+
// are enabled, we need to make every existing import specifier type-only. It may be possible that
|
|
148687
|
+
// some of them don't strictly need to be marked type-only (if they have a value meaning and are
|
|
148688
|
+
// never used in an emitting position). These are allowed to be imported without being type-only,
|
|
148689
|
+
// but the user has clearly already signified that they don't need them to be present at runtime
|
|
148690
|
+
// by placing them in a type-only import. So, just mark each specifier as type-only.
|
|
148691
|
+
var convertExistingToTypeOnly = promoteFromTypeOnly && compilerOptions.preserveValueImports && compilerOptions.isolatedModules;
|
|
148325
148692
|
if (defaultImport) {
|
|
148326
148693
|
ts.Debug.assert(!clause.name, "Cannot add a default import to an import clause that already has one");
|
|
148327
|
-
changes.insertNodeAt(sourceFile, clause.getStart(sourceFile), ts.factory.createIdentifier(defaultImport), { suffix: ", " });
|
|
148694
|
+
changes.insertNodeAt(sourceFile, clause.getStart(sourceFile), ts.factory.createIdentifier(defaultImport.name), { suffix: ", " });
|
|
148328
148695
|
}
|
|
148329
148696
|
if (namedImports.length) {
|
|
148330
|
-
var
|
|
148331
|
-
|
|
148697
|
+
var newSpecifiers = ts.stableSort(namedImports.map(function (namedImport) { return ts.factory.createImportSpecifier((!clause.isTypeOnly || promoteFromTypeOnly) && needsTypeOnly(namedImport),
|
|
148698
|
+
/*propertyName*/ undefined, ts.factory.createIdentifier(namedImport.name)); }), ts.OrganizeImports.compareImportOrExportSpecifiers);
|
|
148332
148699
|
if ((existingSpecifiers === null || existingSpecifiers === void 0 ? void 0 : existingSpecifiers.length) && ts.OrganizeImports.importSpecifiersAreSorted(existingSpecifiers)) {
|
|
148333
|
-
for (var
|
|
148334
|
-
var spec = newSpecifiers_1[
|
|
148335
|
-
|
|
148700
|
+
for (var _b = 0, newSpecifiers_1 = newSpecifiers; _b < newSpecifiers_1.length; _b++) {
|
|
148701
|
+
var spec = newSpecifiers_1[_b];
|
|
148702
|
+
// Organize imports puts type-only import specifiers last, so if we're
|
|
148703
|
+
// adding a non-type-only specifier and converting all the other ones to
|
|
148704
|
+
// type-only, there's no need to ask for the insertion index - it's 0.
|
|
148705
|
+
var insertionIndex = convertExistingToTypeOnly && !spec.isTypeOnly
|
|
148706
|
+
? 0
|
|
148707
|
+
: ts.OrganizeImports.getImportSpecifierInsertionIndex(existingSpecifiers, spec);
|
|
148336
148708
|
var prevSpecifier = clause.namedBindings.elements[insertionIndex - 1];
|
|
148337
148709
|
if (prevSpecifier) {
|
|
148338
148710
|
changes.insertNodeInListAfter(sourceFile, prevSpecifier, spec);
|
|
@@ -148343,8 +148715,8 @@ var ts;
|
|
|
148343
148715
|
}
|
|
148344
148716
|
}
|
|
148345
148717
|
else if (existingSpecifiers === null || existingSpecifiers === void 0 ? void 0 : existingSpecifiers.length) {
|
|
148346
|
-
for (var
|
|
148347
|
-
var spec = newSpecifiers_2[
|
|
148718
|
+
for (var _c = 0, newSpecifiers_2 = newSpecifiers; _c < newSpecifiers_2.length; _c++) {
|
|
148719
|
+
var spec = newSpecifiers_2[_c];
|
|
148348
148720
|
changes.insertNodeInListAfter(sourceFile, ts.last(existingSpecifiers), spec, existingSpecifiers);
|
|
148349
148721
|
}
|
|
148350
148722
|
}
|
|
@@ -148360,8 +148732,14 @@ var ts;
|
|
|
148360
148732
|
}
|
|
148361
148733
|
}
|
|
148362
148734
|
}
|
|
148363
|
-
if (
|
|
148735
|
+
if (promoteFromTypeOnly) {
|
|
148364
148736
|
changes.delete(sourceFile, ts.getTypeKeywordOfTypeOnlyImport(clause, sourceFile));
|
|
148737
|
+
if (convertExistingToTypeOnly && existingSpecifiers) {
|
|
148738
|
+
for (var _d = 0, existingSpecifiers_1 = existingSpecifiers; _d < existingSpecifiers_1.length; _d++) {
|
|
148739
|
+
var specifier = existingSpecifiers_1[_d];
|
|
148740
|
+
changes.insertModifierBefore(sourceFile, 151 /* TypeKeyword */, specifier);
|
|
148741
|
+
}
|
|
148742
|
+
}
|
|
148365
148743
|
}
|
|
148366
148744
|
function addElementToBindingPattern(bindingPattern, name, propertyName) {
|
|
148367
148745
|
var element = ts.factory.createBindingElement(/*dotDotDotToken*/ undefined, propertyName, name);
|
|
@@ -148385,44 +148763,53 @@ var ts;
|
|
|
148385
148763
|
var quote = ts.getQuoteFromPreference(quotePreference);
|
|
148386
148764
|
return "import(" + quote + moduleSpecifier + quote + ").";
|
|
148387
148765
|
}
|
|
148388
|
-
function
|
|
148389
|
-
var _a
|
|
148766
|
+
function needsTypeOnly(_a) {
|
|
148767
|
+
var addAsTypeOnly = _a.addAsTypeOnly;
|
|
148768
|
+
return addAsTypeOnly === 2 /* Required */;
|
|
148769
|
+
}
|
|
148770
|
+
function getNewImports(moduleSpecifier, quotePreference, defaultImport, namedImports, namespaceLikeImport) {
|
|
148390
148771
|
var quotedModuleSpecifier = ts.makeStringLiteral(moduleSpecifier, quotePreference);
|
|
148391
148772
|
var statements;
|
|
148392
|
-
if (
|
|
148393
|
-
|
|
148773
|
+
if (defaultImport !== undefined || (namedImports === null || namedImports === void 0 ? void 0 : namedImports.length)) {
|
|
148774
|
+
var topLevelTypeOnly_1 = (!defaultImport || needsTypeOnly(defaultImport)) && ts.every(namedImports, needsTypeOnly);
|
|
148775
|
+
statements = ts.combine(statements, ts.makeImport(defaultImport && ts.factory.createIdentifier(defaultImport.name), namedImports === null || namedImports === void 0 ? void 0 : namedImports.map(function (_a) {
|
|
148776
|
+
var addAsTypeOnly = _a.addAsTypeOnly, name = _a.name;
|
|
148777
|
+
return ts.factory.createImportSpecifier(!topLevelTypeOnly_1 && addAsTypeOnly === 2 /* Required */,
|
|
148778
|
+
/*propertyName*/ undefined, ts.factory.createIdentifier(name));
|
|
148779
|
+
}), moduleSpecifier, quotePreference, topLevelTypeOnly_1));
|
|
148394
148780
|
}
|
|
148395
|
-
var namespaceLikeImport = imports.namespaceLikeImport, typeOnly = imports.typeOnly;
|
|
148396
148781
|
if (namespaceLikeImport) {
|
|
148397
148782
|
var declaration = namespaceLikeImport.importKind === 3 /* CommonJS */
|
|
148398
148783
|
? ts.factory.createImportEqualsDeclaration(
|
|
148399
148784
|
/*decorators*/ undefined,
|
|
148400
|
-
/*modifiers*/ undefined,
|
|
148785
|
+
/*modifiers*/ undefined, needsTypeOnly(namespaceLikeImport), ts.factory.createIdentifier(namespaceLikeImport.name), ts.factory.createExternalModuleReference(quotedModuleSpecifier))
|
|
148401
148786
|
: ts.factory.createImportDeclaration(
|
|
148402
148787
|
/*decorators*/ undefined,
|
|
148403
|
-
/*modifiers*/ undefined, ts.factory.createImportClause(
|
|
148788
|
+
/*modifiers*/ undefined, ts.factory.createImportClause(needsTypeOnly(namespaceLikeImport),
|
|
148404
148789
|
/*name*/ undefined, ts.factory.createNamespaceImport(ts.factory.createIdentifier(namespaceLikeImport.name))), quotedModuleSpecifier,
|
|
148405
148790
|
/*assertClause*/ undefined);
|
|
148406
148791
|
statements = ts.combine(statements, declaration);
|
|
148407
148792
|
}
|
|
148408
148793
|
return ts.Debug.checkDefined(statements);
|
|
148409
148794
|
}
|
|
148410
|
-
function getNewRequires(moduleSpecifier, quotePreference,
|
|
148411
|
-
var _a, _b;
|
|
148795
|
+
function getNewRequires(moduleSpecifier, quotePreference, defaultImport, namedImports, namespaceLikeImport) {
|
|
148412
148796
|
var quotedModuleSpecifier = ts.makeStringLiteral(moduleSpecifier, quotePreference);
|
|
148413
148797
|
var statements;
|
|
148414
148798
|
// const { default: foo, bar, etc } = require('./mod');
|
|
148415
|
-
if (
|
|
148416
|
-
var bindingElements = (
|
|
148417
|
-
|
|
148418
|
-
|
|
148799
|
+
if (defaultImport || (namedImports === null || namedImports === void 0 ? void 0 : namedImports.length)) {
|
|
148800
|
+
var bindingElements = (namedImports === null || namedImports === void 0 ? void 0 : namedImports.map(function (_a) {
|
|
148801
|
+
var name = _a.name;
|
|
148802
|
+
return ts.factory.createBindingElement(/*dotDotDotToken*/ undefined, /*propertyName*/ undefined, name);
|
|
148803
|
+
})) || [];
|
|
148804
|
+
if (defaultImport) {
|
|
148805
|
+
bindingElements.unshift(ts.factory.createBindingElement(/*dotDotDotToken*/ undefined, "default", defaultImport.name));
|
|
148419
148806
|
}
|
|
148420
148807
|
var declaration = createConstEqualsRequireDeclaration(ts.factory.createObjectBindingPattern(bindingElements), quotedModuleSpecifier);
|
|
148421
148808
|
statements = ts.combine(statements, declaration);
|
|
148422
148809
|
}
|
|
148423
148810
|
// const foo = require('./mod');
|
|
148424
|
-
if (
|
|
148425
|
-
var declaration = createConstEqualsRequireDeclaration(
|
|
148811
|
+
if (namespaceLikeImport) {
|
|
148812
|
+
var declaration = createConstEqualsRequireDeclaration(namespaceLikeImport.name, quotedModuleSpecifier);
|
|
148426
148813
|
statements = ts.combine(statements, declaration);
|
|
148427
148814
|
}
|
|
148428
148815
|
return ts.Debug.checkDefined(statements);
|
|
@@ -152334,7 +152721,7 @@ var ts;
|
|
|
152334
152721
|
return ts.factory.createQualifiedName(replaceFirstIdentifierOfEntityName(name.left, newIdentifier), name.right);
|
|
152335
152722
|
}
|
|
152336
152723
|
function importSymbols(importAdder, symbols) {
|
|
152337
|
-
symbols.forEach(function (s) { return importAdder.addImportFromExportedSymbol(s, /*
|
|
152724
|
+
symbols.forEach(function (s) { return importAdder.addImportFromExportedSymbol(s, /*isValidTypeOnlyUseSite*/ true); });
|
|
152338
152725
|
}
|
|
152339
152726
|
codefix.importSymbols = importSymbols;
|
|
152340
152727
|
})(codefix = ts.codefix || (ts.codefix = {}));
|
|
@@ -152806,7 +153193,7 @@ var ts;
|
|
|
152806
153193
|
if (!ts.isIdentifier(element.name) || element.initializer) {
|
|
152807
153194
|
return undefined;
|
|
152808
153195
|
}
|
|
152809
|
-
importSpecifiers.push(ts.factory.createImportSpecifier(ts.tryCast(element.propertyName, ts.isIdentifier), element.name));
|
|
153196
|
+
importSpecifiers.push(ts.factory.createImportSpecifier(/*isTypeOnly*/ false, ts.tryCast(element.propertyName, ts.isIdentifier), element.name));
|
|
152810
153197
|
}
|
|
152811
153198
|
if (importSpecifiers.length) {
|
|
152812
153199
|
return ts.factory.createNamedImports(importSpecifiers);
|
|
@@ -153553,10 +153940,10 @@ var ts;
|
|
|
153553
153940
|
}
|
|
153554
153941
|
}
|
|
153555
153942
|
function makeImportSpecifier(propertyName, name) {
|
|
153556
|
-
return ts.factory.createImportSpecifier(propertyName === name ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name));
|
|
153943
|
+
return ts.factory.createImportSpecifier(/*isTypeOnly*/ false, propertyName === name ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name));
|
|
153557
153944
|
}
|
|
153558
153945
|
function makeExportSpecifier(propertyName, name) {
|
|
153559
|
-
return ts.factory.createExportSpecifier(propertyName === name ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name));
|
|
153946
|
+
return ts.factory.createExportSpecifier(/*isTypeOnly*/ false, propertyName === name ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name));
|
|
153560
153947
|
}
|
|
153561
153948
|
})(refactor = ts.refactor || (ts.refactor = {}));
|
|
153562
153949
|
})(ts || (ts = {}));
|
|
@@ -153669,7 +154056,7 @@ var ts;
|
|
|
153669
154056
|
}
|
|
153670
154057
|
var importSpecifiers = [];
|
|
153671
154058
|
exportNameToImportName.forEach(function (name, propertyName) {
|
|
153672
|
-
importSpecifiers.push(ts.factory.createImportSpecifier(name === propertyName ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name)));
|
|
154059
|
+
importSpecifiers.push(ts.factory.createImportSpecifier(/*isTypeOnly*/ false, name === propertyName ? undefined : ts.factory.createIdentifier(propertyName), ts.factory.createIdentifier(name)));
|
|
153673
154060
|
});
|
|
153674
154061
|
var importDecl = toConvert.parent.parent;
|
|
153675
154062
|
if (usedAsNamespaceOrDefault && !allowSyntheticDefaultImports) {
|
|
@@ -153740,7 +154127,7 @@ var ts;
|
|
|
153740
154127
|
changes.replaceNode(sourceFile, toConvert, ts.factory.createNamespaceImport(ts.factory.createIdentifier(namespaceImportName)));
|
|
153741
154128
|
if (neededNamedImports.size) {
|
|
153742
154129
|
var newNamedImports = ts.arrayFrom(neededNamedImports.values()).map(function (element) {
|
|
153743
|
-
return ts.factory.createImportSpecifier(element.propertyName && ts.factory.createIdentifier(element.propertyName.text), ts.factory.createIdentifier(element.name.text));
|
|
154130
|
+
return ts.factory.createImportSpecifier(element.isTypeOnly, element.propertyName && ts.factory.createIdentifier(element.propertyName.text), ts.factory.createIdentifier(element.name.text));
|
|
153744
154131
|
});
|
|
153745
154132
|
changes.insertNodeAfter(sourceFile, toConvert.parent.parent, updateImport(importDecl, /*defaultImportName*/ undefined, newNamedImports));
|
|
153746
154133
|
}
|
|
@@ -156442,7 +156829,7 @@ var ts;
|
|
|
156442
156829
|
function makeImportOrRequire(defaultImport, imports, path, useEs6Imports, quotePreference) {
|
|
156443
156830
|
path = ts.ensurePathIsNonModuleName(path);
|
|
156444
156831
|
if (useEs6Imports) {
|
|
156445
|
-
var specifiers = imports.map(function (i) { return ts.factory.createImportSpecifier(/*propertyName*/ undefined, ts.factory.createIdentifier(i)); });
|
|
156832
|
+
var specifiers = imports.map(function (i) { return ts.factory.createImportSpecifier(/*isTypeOnly*/ false, /*propertyName*/ undefined, ts.factory.createIdentifier(i)); });
|
|
156446
156833
|
return ts.makeImportIfNecessary(defaultImport, specifiers, path, quotePreference);
|
|
156447
156834
|
}
|
|
156448
156835
|
else {
|