From 5348903e8891b39c7b8b0400b2c6e5e426e11175 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Wed, 22 Mar 2023 14:46:54 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Pick=20PR=20#53385=20(Add=20miss?= =?UTF-8?q?ing=20ambient=20check=20to=20`verba...)=20into=20release-5.0=20?= =?UTF-8?q?(#53389)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Andrew Branch --- src/compiler/checker.ts | 4 ++-- ...erbatimModuleSyntaxDeclarationFile.symbols | 24 +++++++++++++++++++ .../verbatimModuleSyntaxDeclarationFile.types | 22 +++++++++++++++++ ...erbatimModuleSyntaxNoElisionCJS.errors.txt | 5 +--- .../verbatimModuleSyntaxDeclarationFile.ts | 15 ++++++++++++ 5 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 tests/baselines/reference/verbatimModuleSyntaxDeclarationFile.symbols create mode 100644 tests/baselines/reference/verbatimModuleSyntaxDeclarationFile.types create mode 100644 tests/cases/conformance/externalModules/verbatimModuleSyntaxDeclarationFile.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5e374efbfba..c962f183997 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -44164,7 +44164,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (getAllSymbolFlags(sym) & SymbolFlags.Value) { // However if it is a value, we need to check it's being used correctly checkExpressionCached(id); - if (!isIllegalExportDefaultInCJS && compilerOptions.verbatimModuleSyntax && getTypeOnlyAliasDeclaration(sym, SymbolFlags.Value)) { + if (!isIllegalExportDefaultInCJS && !(node.flags & NodeFlags.Ambient) && compilerOptions.verbatimModuleSyntax && getTypeOnlyAliasDeclaration(sym, SymbolFlags.Value)) { error(id, node.isExportEquals ? Diagnostics.An_export_declaration_must_reference_a_real_value_when_verbatimModuleSyntax_is_enabled_but_0_resolves_to_a_type_only_declaration @@ -44172,7 +44172,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { idText(id)); } } - else if (!isIllegalExportDefaultInCJS && compilerOptions.verbatimModuleSyntax) { + else if (!isIllegalExportDefaultInCJS && !(node.flags & NodeFlags.Ambient) && compilerOptions.verbatimModuleSyntax) { error(id, node.isExportEquals ? Diagnostics.An_export_declaration_must_reference_a_value_when_verbatimModuleSyntax_is_enabled_but_0_only_refers_to_a_type diff --git a/tests/baselines/reference/verbatimModuleSyntaxDeclarationFile.symbols b/tests/baselines/reference/verbatimModuleSyntaxDeclarationFile.symbols new file mode 100644 index 00000000000..ff0b6e6691a --- /dev/null +++ b/tests/baselines/reference/verbatimModuleSyntaxDeclarationFile.symbols @@ -0,0 +1,24 @@ +=== tests/cases/conformance/externalModules/type1.d.ts === +declare namespace NS { +>NS : Symbol(NS, Decl(type1.d.ts, 0, 0)) + + type A = object; +>A : Symbol(A, Decl(type1.d.ts, 0, 22)) +} + +export = NS; +>NS : Symbol(NS, Decl(type1.d.ts, 0, 0)) + +export as namespace MyTypes; +>MyTypes : Symbol(MyTypes, Decl(type1.d.ts, 4, 12)) + +=== tests/cases/conformance/externalModules/type2.d.ts === +import type * as NS from './type1'; +>NS : Symbol(NS, Decl(type2.d.ts, 0, 11)) + +export = NS; +>NS : Symbol(NS, Decl(type2.d.ts, 0, 11)) + +export as namespace ModuleATypes; +>ModuleATypes : Symbol(ModuleATypes, Decl(type2.d.ts, 2, 12)) + diff --git a/tests/baselines/reference/verbatimModuleSyntaxDeclarationFile.types b/tests/baselines/reference/verbatimModuleSyntaxDeclarationFile.types new file mode 100644 index 00000000000..3191db67a32 --- /dev/null +++ b/tests/baselines/reference/verbatimModuleSyntaxDeclarationFile.types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/externalModules/type1.d.ts === +declare namespace NS { + type A = object; +>A : object +} + +export = NS; +>NS : any + +export as namespace MyTypes; +>MyTypes : error + +=== tests/cases/conformance/externalModules/type2.d.ts === +import type * as NS from './type1'; +>NS : error + +export = NS; +>NS : any + +export as namespace ModuleATypes; +>ModuleATypes : error + diff --git a/tests/baselines/reference/verbatimModuleSyntaxNoElisionCJS.errors.txt b/tests/baselines/reference/verbatimModuleSyntaxNoElisionCJS.errors.txt index f035e2365b7..65c88131963 100644 --- a/tests/baselines/reference/verbatimModuleSyntaxNoElisionCJS.errors.txt +++ b/tests/baselines/reference/verbatimModuleSyntaxNoElisionCJS.errors.txt @@ -1,7 +1,6 @@ /a.ts(2,10): error TS1282: An 'export =' declaration must reference a value when 'verbatimModuleSyntax' is enabled, but 'I' only refers to a type. /b.ts(1,1): error TS1484: 'I' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled. /d.ts(3,10): error TS1283: An 'export =' declaration must reference a real value when 'verbatimModuleSyntax' is enabled, but 'J' resolves to a type-only declaration. -/e.d.ts(2,10): error TS1282: An 'export =' declaration must reference a value when 'verbatimModuleSyntax' is enabled, but 'I' only refers to a type. ==== /a.ts (1 errors) ==== @@ -29,11 +28,9 @@ ~ !!! error TS1283: An 'export =' declaration must reference a real value when 'verbatimModuleSyntax' is enabled, but 'J' resolves to a type-only declaration. -==== /e.d.ts (1 errors) ==== +==== /e.d.ts (0 errors) ==== interface I {} export = I; - ~ -!!! error TS1282: An 'export =' declaration must reference a value when 'verbatimModuleSyntax' is enabled, but 'I' only refers to a type. ==== /f.ts (0 errors) ==== import type I = require("./e"); diff --git a/tests/cases/conformance/externalModules/verbatimModuleSyntaxDeclarationFile.ts b/tests/cases/conformance/externalModules/verbatimModuleSyntaxDeclarationFile.ts new file mode 100644 index 00000000000..e5ae2601801 --- /dev/null +++ b/tests/cases/conformance/externalModules/verbatimModuleSyntaxDeclarationFile.ts @@ -0,0 +1,15 @@ +// @verbatimModuleSyntax: true + +// @Filename: type1.d.ts +declare namespace NS { + type A = object; +} + +export = NS; +export as namespace MyTypes; + +// @Filename: type2.d.ts +import type * as NS from './type1'; + +export = NS; +export as namespace ModuleATypes;