Fix mistakenly disallowed default export under erasableSyntaxOnly (#61210)

This commit is contained in:
Jake Bailey
2025-02-18 08:06:11 -08:00
committed by GitHub
parent 0f4737e0d5
commit c9cb6c3c34
10 changed files with 69 additions and 1 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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))

View File

@@ -179,3 +179,15 @@ export = foo;
>foo : () => void
> : ^^^^^^
=== esm.mts ===
const foo = 1234;
>foo : 1234
> : ^^^^
>1234 : 1234
> : ^^^^
export default foo;
>foo : 1234
> : ^^^^

View File

@@ -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;

View File

@@ -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))

View File

@@ -154,3 +154,15 @@ export = foo;
>foo : () => void
> : ^^^^^^
=== esm.d.mts ===
declare const foo = 1234;
>foo : 1234
> : ^^^^
>1234 : 1234
> : ^^^^
export default foo;
>foo : 1234
> : ^^^^

View File

@@ -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;

View File

@@ -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;