Skip to content

Commit c9cb6c3

Browse files
authored
Fix mistakenly disallowed default export under erasableSyntaxOnly (#61210)
1 parent 0f4737e commit c9cb6c3

10 files changed

+69
-1
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47974,7 +47974,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4797447974
return;
4797547975
}
4797647976

47977-
if (compilerOptions.erasableSyntaxOnly && !(node.flags & NodeFlags.Ambient)) {
47977+
if (compilerOptions.erasableSyntaxOnly && node.isExportEquals && !(node.flags & NodeFlags.Ambient)) {
4797847978
error(node, Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled);
4797947979
}
4798047980
const container = node.parent.kind === SyntaxKind.SourceFile ? node.parent : node.parent.parent as ModuleDeclaration;

tests/baselines/reference/erasableSyntaxOnly.errors.txt

+5
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,9 @@ index.ts(28,12): error TS1294: This syntax is not allowed when 'erasableSyntaxOn
104104
==== other.d.cts (0 errors) ====
105105
declare function foo(): void;
106106
export = foo;
107+
108+
109+
==== esm.mts (0 errors) ====
110+
const foo = 1234;
111+
export default foo;
107112

tests/baselines/reference/erasableSyntaxOnly.js

+8
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ export = foo;
7474
//// [other.d.cts]
7575
declare function foo(): void;
7676
export = foo;
77+
78+
79+
//// [esm.mts]
80+
const foo = 1234;
81+
export default foo;
7782

7883

7984
//// [index.js]
@@ -119,3 +124,6 @@ var MyClassOk = /** @class */ (function () {
119124
"use strict";
120125
var foo = require("./other.cjs");
121126
module.exports = foo;
127+
//// [esm.mjs]
128+
var foo = 1234;
129+
export default foo;

tests/baselines/reference/erasableSyntaxOnly.symbols

+8
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,11 @@ declare function foo(): void;
133133
export = foo;
134134
>foo : Symbol(foo, Decl(other.d.cts, 0, 0))
135135

136+
137+
=== esm.mts ===
138+
const foo = 1234;
139+
>foo : Symbol(foo, Decl(esm.mts, 0, 5))
140+
141+
export default foo;
142+
>foo : Symbol(foo, Decl(esm.mts, 0, 5))
143+

tests/baselines/reference/erasableSyntaxOnly.types

+12
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,15 @@ export = foo;
179179
>foo : () => void
180180
> : ^^^^^^
181181

182+
183+
=== esm.mts ===
184+
const foo = 1234;
185+
>foo : 1234
186+
> : ^^^^
187+
>1234 : 1234
188+
> : ^^^^
189+
190+
export default foo;
191+
>foo : 1234
192+
> : ^^^^
193+

tests/baselines/reference/erasableSyntaxOnlyDeclaration.errors.txt

+5
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,9 @@ index.d.ts(1,1): error TS1046: Top-level declarations in .d.ts files must start
6565
==== other.d.cts (0 errors) ====
6666
declare function foo(): void;
6767
export = foo;
68+
69+
70+
==== esm.d.mts (0 errors) ====
71+
declare const foo = 1234;
72+
export default foo;
6873

tests/baselines/reference/erasableSyntaxOnlyDeclaration.symbols

+8
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,11 @@ declare function foo(): void;
112112
export = foo;
113113
>foo : Symbol(foo, Decl(other.d.cts, 0, 0))
114114

115+
116+
=== esm.d.mts ===
117+
declare const foo = 1234;
118+
>foo : Symbol(foo, Decl(esm.d.mts, 0, 13))
119+
120+
export default foo;
121+
>foo : Symbol(foo, Decl(esm.d.mts, 0, 13))
122+

tests/baselines/reference/erasableSyntaxOnlyDeclaration.types

+12
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,15 @@ export = foo;
154154
>foo : () => void
155155
> : ^^^^^^
156156

157+
158+
=== esm.d.mts ===
159+
declare const foo = 1234;
160+
>foo : 1234
161+
> : ^^^^
162+
>1234 : 1234
163+
> : ^^^^
164+
165+
export default foo;
166+
>foo : 1234
167+
> : ^^^^
168+

tests/cases/compiler/erasableSyntaxOnly.ts

+5
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,8 @@ export = foo;
7474
// @filename: other.d.cts
7575
declare function foo(): void;
7676
export = foo;
77+
78+
79+
// @filename: esm.mts
80+
const foo = 1234;
81+
export default foo;

tests/cases/compiler/erasableSyntaxOnlyDeclaration.ts

+5
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,8 @@ export = foo;
6666
// @filename: other.d.cts
6767
declare function foo(): void;
6868
export = foo;
69+
70+
71+
// @filename: esm.d.mts
72+
declare const foo = 1234;
73+
export default foo;

0 commit comments

Comments
 (0)