Fix false verbatimModuleSyntax error on export namespace in ESM (#52555)

This commit is contained in:
Andrew Branch
2023-02-03 12:32:01 -08:00
committed by GitHub
parent c828562eb4
commit ea47fb1405
10 changed files with 189 additions and 67 deletions

View File

@@ -43344,7 +43344,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
getNodeLinks(node).flags |= NodeCheckFlags.LexicalModuleMergesWithClass;
}
}
if (compilerOptions.verbatimModuleSyntax && node.parent.kind === SyntaxKind.SourceFile) {
if (compilerOptions.verbatimModuleSyntax &&
node.parent.kind === SyntaxKind.SourceFile &&
(moduleKind === ModuleKind.CommonJS || node.parent.impliedNodeFormat === ModuleKind.CommonJS)
) {
const exportModifier = node.modifiers?.find(m => m.kind === SyntaxKind.ExportKeyword);
if (exportModifier) {
error(exportModifier, Diagnostics.A_top_level_export_modifier_cannot_be_used_on_value_declarations_in_a_CommonJS_module_when_verbatimModuleSyntax_is_enabled);