From 8fdbd54160e5a6796a2c2522222553e79d61ec7c Mon Sep 17 00:00:00 2001 From: TypeScript Bot <23042052+typescript-bot@users.noreply.github.com> Date: Tue, 25 Feb 2025 22:46:11 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Pick=20PR=20#61210=20(Fix=20mist?= =?UTF-8?q?akenly=20disallowed=20default=20e...)=20into=20release-5.8=20(#?= =?UTF-8?q?61237)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com> --- src/compiler/checker.ts | 2 +- .../reference/erasableSyntaxOnly.errors.txt | 5 +++++ tests/baselines/reference/erasableSyntaxOnly.js | 8 ++++++++ tests/baselines/reference/erasableSyntaxOnly.symbols | 8 ++++++++ tests/baselines/reference/erasableSyntaxOnly.types | 12 ++++++++++++ .../erasableSyntaxOnlyDeclaration.errors.txt | 5 +++++ .../reference/erasableSyntaxOnlyDeclaration.symbols | 8 ++++++++ .../reference/erasableSyntaxOnlyDeclaration.types | 12 ++++++++++++ tests/cases/compiler/erasableSyntaxOnly.ts | 5 +++++ .../cases/compiler/erasableSyntaxOnlyDeclaration.ts | 5 +++++ 10 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index abd6fd4bf2e8d..8797dbbf80137 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -47974,7 +47974,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { return; } - if (compilerOptions.erasableSyntaxOnly && !(node.flags & NodeFlags.Ambient)) { + if (compilerOptions.erasableSyntaxOnly && node.isExportEquals && !(node.flags & NodeFlags.Ambient)) { error(node, Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled); } const container = node.parent.kind === SyntaxKind.SourceFile ? node.parent : node.parent.parent as ModuleDeclaration; diff --git a/tests/baselines/reference/erasableSyntaxOnly.errors.txt b/tests/baselines/reference/erasableSyntaxOnly.errors.txt index 39a724aa00c51..2005ef65de8e7 100644 --- a/tests/baselines/reference/erasableSyntaxOnly.errors.txt +++ b/tests/baselines/reference/erasableSyntaxOnly.errors.txt @@ -104,4 +104,9 @@ index.ts(28,12): error TS1294: This syntax is not allowed when 'erasableSyntaxOn ==== other.d.cts (0 errors) ==== declare function foo(): void; export = foo; + + +==== esm.mts (0 errors) ==== + const foo = 1234; + export default foo; \ No newline at end of file diff --git a/tests/baselines/reference/erasableSyntaxOnly.js b/tests/baselines/reference/erasableSyntaxOnly.js index 1d7393620df4d..9edf749d7b038 100644 --- a/tests/baselines/reference/erasableSyntaxOnly.js +++ b/tests/baselines/reference/erasableSyntaxOnly.js @@ -74,6 +74,11 @@ export = foo; //// [other.d.cts] declare function foo(): void; export = foo; + + +//// [esm.mts] +const foo = 1234; +export default foo; //// [index.js] @@ -119,3 +124,6 @@ var MyClassOk = /** @class */ (function () { "use strict"; var foo = require("./other.cjs"); module.exports = foo; +//// [esm.mjs] +var foo = 1234; +export default foo; diff --git a/tests/baselines/reference/erasableSyntaxOnly.symbols b/tests/baselines/reference/erasableSyntaxOnly.symbols index f0220004341b3..8e057dc990217 100644 --- a/tests/baselines/reference/erasableSyntaxOnly.symbols +++ b/tests/baselines/reference/erasableSyntaxOnly.symbols @@ -133,3 +133,11 @@ declare function foo(): void; export = foo; >foo : Symbol(foo, Decl(other.d.cts, 0, 0)) + +=== esm.mts === +const foo = 1234; +>foo : Symbol(foo, Decl(esm.mts, 0, 5)) + +export default foo; +>foo : Symbol(foo, Decl(esm.mts, 0, 5)) + diff --git a/tests/baselines/reference/erasableSyntaxOnly.types b/tests/baselines/reference/erasableSyntaxOnly.types index 599a8d2125ead..4d4ddaea49701 100644 --- a/tests/baselines/reference/erasableSyntaxOnly.types +++ b/tests/baselines/reference/erasableSyntaxOnly.types @@ -179,3 +179,15 @@ export = foo; >foo : () => void > : ^^^^^^ + +=== esm.mts === +const foo = 1234; +>foo : 1234 +> : ^^^^ +>1234 : 1234 +> : ^^^^ + +export default foo; +>foo : 1234 +> : ^^^^ + diff --git a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt index 7bc78e382b7ed..fdb4d96f8498b 100644 --- a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt +++ b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt @@ -65,4 +65,9 @@ index.d.ts(1,1): error TS1046: Top-level declarations in .d.ts files must start ==== other.d.cts (0 errors) ==== declare function foo(): void; export = foo; + + +==== esm.d.mts (0 errors) ==== + declare const foo = 1234; + export default foo; \ No newline at end of file diff --git a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols index 4f439b211c5c3..2763999d6468b 100644 --- a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols +++ b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols @@ -112,3 +112,11 @@ declare function foo(): void; export = foo; >foo : Symbol(foo, Decl(other.d.cts, 0, 0)) + +=== esm.d.mts === +declare const foo = 1234; +>foo : Symbol(foo, Decl(esm.d.mts, 0, 13)) + +export default foo; +>foo : Symbol(foo, Decl(esm.d.mts, 0, 13)) + diff --git a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.types b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.types index 031eb9bbb59cb..053aa1b60d2e4 100644 --- a/tests/baselines/reference/erasableSyntaxOnlyDeclaration.types +++ b/tests/baselines/reference/erasableSyntaxOnlyDeclaration.types @@ -154,3 +154,15 @@ export = foo; >foo : () => void > : ^^^^^^ + +=== esm.d.mts === +declare const foo = 1234; +>foo : 1234 +> : ^^^^ +>1234 : 1234 +> : ^^^^ + +export default foo; +>foo : 1234 +> : ^^^^ + diff --git a/tests/cases/compiler/erasableSyntaxOnly.ts b/tests/cases/compiler/erasableSyntaxOnly.ts index 6a76e80337e11..d2ff6d72ce8f3 100644 --- a/tests/cases/compiler/erasableSyntaxOnly.ts +++ b/tests/cases/compiler/erasableSyntaxOnly.ts @@ -74,3 +74,8 @@ export = foo; // @filename: other.d.cts declare function foo(): void; export = foo; + + +// @filename: esm.mts +const foo = 1234; +export default foo; diff --git a/tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts b/tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts index f87e2346f094b..3a986719a160c 100644 --- a/tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts +++ b/tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts @@ -66,3 +66,8 @@ export = foo; // @filename: other.d.cts declare function foo(): void; export = foo; + + +// @filename: esm.d.mts +declare const foo = 1234; +export default foo;