@@ -721,6 +721,7 @@ namespace ts {
721
721
getLocalTypeParametersOfClassOrInterfaceOrTypeAlias,
722
722
isDeclarationVisible,
723
723
isPropertyAccessible,
724
+ getTypeOnlyAliasDeclaration,
724
725
};
725
726
726
727
function getResolvedSignatureWorker(nodeIn: CallLikeExpression, candidatesOutArray: Signature[] | undefined, argumentCount: number | undefined, checkMode: CheckMode): Signature | undefined {
@@ -2203,8 +2204,7 @@ namespace ts {
2203
2204
if (!isValidTypeOnlyAliasUseSite(useSite)) {
2204
2205
const typeOnlyDeclaration = getTypeOnlyAliasDeclaration(symbol);
2205
2206
if (typeOnlyDeclaration) {
2206
- const isExport = typeOnlyDeclarationIsExport(typeOnlyDeclaration);
2207
- const message = isExport
2207
+ const message = typeOnlyDeclaration.kind === SyntaxKind.ExportSpecifier
2208
2208
? Diagnostics._0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type
2209
2209
: Diagnostics._0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type;
2210
2210
const unescapedName = unescapeLeadingUnderscores(name);
@@ -2222,7 +2222,7 @@ namespace ts {
2222
2222
diagnostic,
2223
2223
createDiagnosticForNode(
2224
2224
typeOnlyDeclaration,
2225
- typeOnlyDeclarationIsExport( typeOnlyDeclaration) ? Diagnostics._0_was_exported_here : Diagnostics._0_was_imported_here,
2225
+ typeOnlyDeclaration.kind === SyntaxKind.ExportSpecifier ? Diagnostics._0_was_exported_here : Diagnostics._0_was_imported_here,
2226
2226
unescapedName));
2227
2227
}
2228
2228
@@ -2590,17 +2590,15 @@ namespace ts {
2590
2590
function checkAndReportErrorForResolvingImportAliasToTypeOnlySymbol(node: ImportEqualsDeclaration, resolved: Symbol | undefined) {
2591
2591
if (markSymbolOfAliasDeclarationIfTypeOnly(node, /*immediateTarget*/ undefined, resolved, /*overwriteEmpty*/ false) && !node.isTypeOnly) {
2592
2592
const typeOnlyDeclaration = getTypeOnlyAliasDeclaration(getSymbolOfNode(node))!;
2593
- const isExport = typeOnlyDeclarationIsExport( typeOnlyDeclaration) ;
2593
+ const isExport = typeOnlyDeclaration.kind === SyntaxKind.ExportSpecifier ;
2594
2594
const message = isExport
2595
2595
? Diagnostics.An_import_alias_cannot_reference_a_declaration_that_was_exported_using_export_type
2596
2596
: Diagnostics.An_import_alias_cannot_reference_a_declaration_that_was_imported_using_import_type;
2597
2597
const relatedMessage = isExport
2598
2598
? Diagnostics._0_was_exported_here
2599
2599
: Diagnostics._0_was_imported_here;
2600
2600
2601
- // Non-null assertion is safe because the optionality comes from ImportClause,
2602
- // but if an ImportClause was the typeOnlyDeclaration, it had to have a `name`.
2603
- const name = unescapeLeadingUnderscores(typeOnlyDeclaration.name!.escapedText);
2601
+ const name = unescapeLeadingUnderscores(typeOnlyDeclaration.name.escapedText);
2604
2602
addRelatedInfo(error(node.moduleReference, message), createDiagnosticForNode(typeOnlyDeclaration, relatedMessage, name));
2605
2603
}
2606
2604
}
@@ -3054,13 +3052,13 @@ namespace ts {
3054
3052
* and issue an error if so.
3055
3053
*
3056
3054
* @param aliasDeclaration The alias declaration not marked as type-only
3055
+ * @param immediateTarget The symbol to which the alias declaration immediately resolves
3056
+ * @param finalTarget The symbol to which the alias declaration ultimately resolves
3057
+ * @param overwriteEmpty Checks `resolvesToSymbol` for type-only declarations even if `aliasDeclaration`
3057
3058
* has already been marked as not resolving to a type-only alias. Used when recursively resolving qualified
3058
3059
* names of import aliases, e.g. `import C = a.b.C`. If namespace `a` is not found to be type-only, the
3059
3060
* import declaration will initially be marked as not resolving to a type-only symbol. But, namespace `b`
3060
3061
* must still be checked for a type-only marker, overwriting the previous negative result if found.
3061
- * @param immediateTarget The symbol to which the alias declaration immediately resolves
3062
- * @param finalTarget The symbol to which the alias declaration ultimately resolves
3063
- * @param overwriteEmpty Checks `resolvesToSymbol` for type-only declarations even if `aliasDeclaration`
3064
3062
*/
3065
3063
function markSymbolOfAliasDeclarationIfTypeOnly(
3066
3064
aliasDeclaration: Declaration | undefined,
@@ -3094,7 +3092,7 @@ namespace ts {
3094
3092
}
3095
3093
3096
3094
/** Indicates that a symbol directly or indirectly resolves to a type-only import or export. */
3097
- function getTypeOnlyAliasDeclaration(symbol: Symbol): TypeOnlyCompatibleAliasDeclaration | undefined {
3095
+ function getTypeOnlyAliasDeclaration(symbol: Symbol): TypeOnlyAliasDeclaration | undefined {
3098
3096
if (!(symbol.flags & SymbolFlags.Alias)) {
3099
3097
return undefined;
3100
3098
}
@@ -6536,7 +6534,7 @@ namespace ts {
6536
6534
/*decorators*/ undefined,
6537
6535
/*modifiers*/ undefined,
6538
6536
/*isTypeOnly*/ false,
6539
- factory.createNamedExports(map(flatMap(excessExports, e => getNamesOfDeclaration(e)), id => factory.createExportSpecifier(/*alias*/ undefined, id))),
6537
+ factory.createNamedExports(map(flatMap(excessExports, e => getNamesOfDeclaration(e)), id => factory.createExportSpecifier(/*isTypeOnly*/ false, /* alias*/ undefined, id))),
6540
6538
/*moduleSpecifier*/ undefined
6541
6539
)])
6542
6540
)
@@ -6794,7 +6792,7 @@ namespace ts {
6794
6792
/*decorators*/ undefined,
6795
6793
/*modifiers*/ undefined,
6796
6794
/*isTypeOnly*/ false,
6797
- factory.createNamedExports([factory.createExportSpecifier(alias, localName)])
6795
+ factory.createNamedExports([factory.createExportSpecifier(/*isTypeOnly*/ false, alias, localName)])
6798
6796
),
6799
6797
ModifierFlags.None
6800
6798
);
@@ -6832,7 +6830,7 @@ namespace ts {
6832
6830
/*decorators*/ undefined,
6833
6831
/*modifiers*/ undefined,
6834
6832
/*isTypeOnly*/ false,
6835
- factory.createNamedExports([factory.createExportSpecifier(name, localName)])
6833
+ factory.createNamedExports([factory.createExportSpecifier(/*isTypeOnly*/ false, name, localName)])
6836
6834
),
6837
6835
ModifierFlags.None
6838
6836
);
@@ -6892,7 +6890,7 @@ namespace ts {
6892
6890
/*decorators*/ undefined,
6893
6891
/*modifiers*/ undefined,
6894
6892
/*isTypeOnly*/ false,
6895
- factory.createNamedExports([factory.createExportSpecifier(getInternalSymbolName(symbol, symbolName), symbolName)])
6893
+ factory.createNamedExports([factory.createExportSpecifier(/*isTypeOnly*/ false, getInternalSymbolName(symbol, symbolName), symbolName)])
6896
6894
), ModifierFlags.None);
6897
6895
}
6898
6896
}
@@ -7031,7 +7029,7 @@ namespace ts {
7031
7029
const target = aliasDecl && getTargetOfAliasDeclaration(aliasDecl, /*dontRecursivelyResolve*/ true);
7032
7030
includePrivateSymbol(target || s);
7033
7031
const targetName = target ? getInternalSymbolName(target, unescapeLeadingUnderscores(target.escapedName)) : localName;
7034
- return factory.createExportSpecifier(name === targetName ? undefined : targetName, name);
7032
+ return factory.createExportSpecifier(/*isTypeOnly*/ false, name === targetName ? undefined : targetName, name);
7035
7033
}))
7036
7034
)]);
7037
7035
addResult(factory.createModuleDeclaration(
@@ -7137,7 +7135,7 @@ namespace ts {
7137
7135
/*decorators*/ undefined,
7138
7136
/*modifiers*/ undefined,
7139
7137
/*isTypeOnly*/ false,
7140
- factory.createNamedExports([factory.createExportSpecifier(d.expression, factory.createIdentifier(InternalSymbolName.Default))])
7138
+ factory.createNamedExports([factory.createExportSpecifier(/*isTypeOnly*/ false, d.expression, factory.createIdentifier(InternalSymbolName.Default))])
7141
7139
) : d);
7142
7140
const exportModifierStripped = every(defaultReplaced, d => hasSyntacticModifier(d, ModifierFlags.Export)) ? map(defaultReplaced, removeExportModifier) : defaultReplaced;
7143
7141
fakespace = factory.updateModuleDeclaration(
@@ -7313,6 +7311,7 @@ namespace ts {
7313
7311
/*decorators*/ undefined,
7314
7312
/*modifiers*/ undefined,
7315
7313
factory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, factory.createNamedImports([factory.createImportSpecifier(
7314
+ /*isTypeOnly*/ false,
7316
7315
propertyName && isIdentifier(propertyName) ? factory.createIdentifier(idText(propertyName)) : undefined,
7317
7316
factory.createIdentifier(localName)
7318
7317
)])),
@@ -7424,6 +7423,7 @@ namespace ts {
7424
7423
/*importClause*/ undefined,
7425
7424
factory.createNamedImports([
7426
7425
factory.createImportSpecifier(
7426
+ /*isTypeOnly*/ false,
7427
7427
localName !== verbatimTargetName ? factory.createIdentifier(verbatimTargetName) : undefined,
7428
7428
factory.createIdentifier(localName)
7429
7429
)
@@ -7470,7 +7470,7 @@ namespace ts {
7470
7470
/*decorators*/ undefined,
7471
7471
/*modifiers*/ undefined,
7472
7472
/*isTypeOnly*/ false,
7473
- factory.createNamedExports([factory.createExportSpecifier(localName !== targetName ? targetName : undefined, localName)]),
7473
+ factory.createNamedExports([factory.createExportSpecifier(/*isTypeOnly*/ false, localName !== targetName ? targetName : undefined, localName)]),
7474
7474
specifier
7475
7475
), ModifierFlags.None);
7476
7476
}
@@ -39415,11 +39415,15 @@ namespace ts {
39415
39415
}
39416
39416
39417
39417
function checkGrammarExportDeclaration(node: ExportDeclaration): boolean {
39418
- const isTypeOnlyExportStar = node.isTypeOnly && node.exportClause?.kind !== SyntaxKind.NamedExports;
39419
- if (isTypeOnlyExportStar) {
39420
- grammarErrorOnNode(node, Diagnostics.Only_named_exports_may_use_export_type);
39418
+ if (node.isTypeOnly) {
39419
+ if (node.exportClause?.kind === SyntaxKind.NamedExports) {
39420
+ return checkGrammarNamedImportsOrExports(node.exportClause);
39421
+ }
39422
+ else {
39423
+ return grammarErrorOnNode(node, Diagnostics.Only_named_exports_may_use_export_type);
39424
+ }
39421
39425
}
39422
- return !isTypeOnlyExportStar ;
39426
+ return false ;
39423
39427
}
39424
39428
39425
39429
function checkGrammarModuleElementContext(node: Statement, errorMessage: DiagnosticMessage): boolean {
@@ -43445,9 +43449,24 @@ namespace ts {
43445
43449
if (node.isTypeOnly && node.name && node.namedBindings) {
43446
43450
return grammarErrorOnNode(node, Diagnostics.A_type_only_import_can_specify_a_default_import_or_named_bindings_but_not_both);
43447
43451
}
43452
+ if (node.isTypeOnly && node.namedBindings?.kind === SyntaxKind.NamedImports) {
43453
+ return checkGrammarNamedImportsOrExports(node.namedBindings);
43454
+ }
43448
43455
return false;
43449
43456
}
43450
43457
43458
+ function checkGrammarNamedImportsOrExports(namedBindings: NamedImportsOrExports): boolean {
43459
+ return !!forEach<ImportSpecifier | ExportSpecifier, boolean>(namedBindings.elements, specifier => {
43460
+ if (specifier.isTypeOnly) {
43461
+ return grammarErrorOnFirstToken(
43462
+ specifier,
43463
+ specifier.kind === SyntaxKind.ImportSpecifier
43464
+ ? Diagnostics.The_type_modifier_cannot_be_used_on_a_named_import_when_import_type_is_used_on_its_import_statement
43465
+ : Diagnostics.The_type_modifier_cannot_be_used_on_a_named_export_when_export_type_is_used_on_its_export_statement);
43466
+ }
43467
+ });
43468
+ }
43469
+
43451
43470
function checkGrammarImportCallExpression(node: ImportCall): boolean {
43452
43471
if (moduleKind === ModuleKind.ES2015) {
43453
43472
return grammarErrorOnNode(node, Diagnostics.Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_esnext_commonjs_amd_system_umd_node12_or_nodenext);
0 commit comments